]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
More prefpath fixes.
[lugaru.git] / Source / GameTick.cpp
1 #if PLATFORM_UNIX
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #else
6 #include <direct.h>
7 #endif
8
9 #include <ctime>
10 #include "Game.h"
11
12 using namespace std;
13
14 extern float multiplier;
15 extern XYZ viewer;
16 extern int environment;
17 extern float texscale;
18 extern Terrain terrain;
19 extern FSOUND_SAMPLE    *samp[100];
20 extern int channels[100];
21 extern Sprites sprites;
22 extern int kTextureSize;
23 extern float screenwidth,screenheight;
24 extern float gravity;
25 extern int detail;
26 extern float texdetail;
27 extern Objects objects;
28 extern int slomo;
29 extern float slomodelay;
30 extern bool floatjump;
31 extern float volume;
32 extern Animation animation[animation_count];
33 extern Light light;
34 extern float texdetail;
35 extern GLubyte bloodText[512*512*3];
36 extern GLubyte wolfbloodText[512*512*3];
37 extern float terraindetail;
38 extern float camerashake;
39 extern float woozy;
40 extern float blackout;
41 extern bool cellophane;
42 extern bool musictoggle;
43 extern int difficulty;
44 extern Weapons weapons;
45 extern Person player[maxplayers];
46 extern int numplayers;
47 extern int bloodtoggle;
48 extern bool invertmouse;
49 extern float windvar;
50 extern float precipdelay;
51 extern XYZ viewerfacing;
52 extern bool ambientsound;
53 extern bool mousejump;
54 extern float viewdistance;
55 extern bool freeze;
56 extern bool autoslomo;
57 extern int newnetmessages;
58 extern char netmessages[256];
59 extern bool keyboardfrozen;
60 extern int netdatanew;
61 extern bool loadingstuff;
62 extern char mapname[256];
63 extern XYZ windvector;
64 extern bool buttons[3];
65 extern bool debugmode;
66 static int music1;
67 extern int mainmenu;
68 extern int oldmainmenu;
69 extern bool visibleloading;
70 extern int loadscreencolor;
71 extern float flashamount,flashr,flashg,flashb;
72 extern int flashdelay;
73 extern XYZ envsound[30];
74 extern float envsoundvol[30];
75 extern int numenvsounds;
76 extern float envsoundlife[30];
77 extern float usermousesensitivity;
78 extern bool ismotionblur;
79 extern bool foliage;
80 extern bool trilinear;
81 extern bool damageeffects;
82 extern bool showpoints;
83 extern bool texttoggle;
84 extern bool alwaysblur;
85 extern float gamespeed;
86 extern bool decals;
87 extern bool vblsync;
88 extern bool immediate;
89 extern bool velocityblur;
90 extern int bonus;
91 extern int oldbonus;
92 extern float bonusvalue;
93 extern float bonustotal;
94 extern float bonustime;
95 extern float startbonustotal;
96 extern float tintr,tintg,tintb;
97 extern float bonusnum[100];
98 extern bool skyboxtexture;
99 extern float skyboxr;
100 extern float skyboxg;
101 extern float skyboxb;
102 extern float skyboxlightr;
103 extern float skyboxlightg;
104 extern float skyboxlightb;
105 extern float fadestart;
106 extern float slomospeed;
107 extern float slomofreq;
108 extern int tutoriallevel;
109 extern float smoketex;
110 extern float tutorialstagetime;
111 extern int tutorialstage;
112 extern float tutorialmaxtime;
113 extern float tutorialsuccess;
114 extern bool againbonus;
115 extern bool reversaltrain;
116 extern bool canattack;
117 extern bool cananger;
118 extern float damagedealt;
119 extern float damagetaken;
120 extern int maptype;
121 extern int editoractive;
122 extern int editorpathtype;
123 extern bool oldbuttons[3];
124
125 extern float hostiletime;
126
127 extern bool gamestarted;
128
129 extern int numhotspots;
130 extern int winhotspot;
131 extern int windialogue;
132 extern int killhotspot;
133 extern XYZ hotspot[40];
134 extern int hotspottype[40];
135 extern float hotspotsize[40];
136 extern char hotspottext[40][256];
137 extern int currenthotspot;
138
139 extern int kBitsPerPixel;
140 extern int hostile;
141
142 extern int numaccounts;
143 extern int accountactive;
144 extern int accountdifficulty[10];
145 extern int accountprogress[10];
146 extern float accountpoints[10];
147 extern float accounthighscore[10][50];
148 extern float accountfasttime[10][50];
149 extern bool accountunlocked[10][60];
150 extern char accountname[10][256];
151
152 extern bool stillloading;
153 extern bool winfreeze;
154
155 extern int numfalls;
156 extern int numflipfail;
157 extern int numseen;
158 extern int numstaffattack;
159 extern int numswordattack;
160 extern int numknifeattack;
161 extern int numunarmedattack;
162 extern int numescaped;
163 extern int numflipped;
164 extern int numwallflipped;
165 extern int numthrowkill;
166 extern int numafterkill;
167 extern int numreversals;
168 extern int numattacks;
169 extern int maxalarmed;
170 extern int numresponded;
171
172 extern int numdialogues;
173 extern int numdialogueboxes[max_dialogues];
174 extern int dialoguetype[max_dialogues];
175 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
176 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
177 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
178 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
179 extern char dialoguename[max_dialogues][max_dialoguelength][64];
180 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
181 extern XYZ participantlocation[max_dialogues][10];
182 extern int participantfocus[max_dialogues][max_dialoguelength];
183 extern int participantaction[max_dialogues][max_dialoguelength];
184 extern float participantrotation[max_dialogues][10];
185 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
186 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
187 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
188 extern int indialogue;
189 extern int whichdialogue;
190 extern int directing;
191 extern float dialoguetime;
192 extern int dialoguegonethrough[20];
193
194 extern bool campaign;
195
196 extern float oldgamespeed;
197
198 extern float accountcampaignhighscore[10];
199 extern float accountcampaignfasttime[10];
200 extern float accountcampaignscore[10];
201 extern float accountcampaigntime[10];
202
203 extern int accountcampaignchoicesmade[10];
204 extern int accountcampaignchoices[10][5000];
205 /********************> Tick() <*****/
206 extern FSOUND_STREAM * strm[10];
207 extern "C"      void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
208 extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
209
210 extern void ScreenShot(const char * fname);
211 void Screenshot (void)
212 {
213         char temp[1024];
214         time_t  t = time(NULL);
215         struct  tm *tme = localtime(&t);
216         sprintf(temp, "Screenshots\\Screenshot_%04d_%02d_%02d--%02d_%02d_%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
217
218         mkdir("Screenshots", S_IRWXU);
219         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
220
221         /*FSSpec                                MAC_file;
222         GraphicsExportComponent         QT_exporter;
223         OSErr                           MAC_error_code;
224         CGrafPtr                        MAC_currentPort;
225         GDHandle                        MAC_currentDevice;
226         unsigned char*          MAC_pixels;
227         Rect                            MAC_picture_rectangle;
228         GWorldPtr                       MAC_offscreen_graphics_port;
229
230         static int numscreenshots=0;
231
232         // Make an FSSpec
233         static char buf[256];
234         if(numscreenshots==0){
235         buf[0]=26;
236         buf[1]=':';
237         buf[2]='S';
238         buf[3]='c';
239         buf[4]='r';
240         buf[5]='e';
241         buf[6]='e';
242         buf[7]='n';
243         buf[8]='s';
244         buf[9]='h';
245         buf[10]='o';
246         buf[11]='t';
247         buf[12]='s';
248         buf[13]=':';
249         buf[14]='S';
250         buf[15]='c';
251         buf[16]='r';
252         buf[17]='e';
253         buf[18]='e';
254         buf[19]='n';
255         buf[20]='s';
256         buf[21]='h';
257         buf[22]='o';
258         buf[23]='t';
259         buf[24]='0';
260         buf[25]='0';
261         buf[26]='0';
262         }
263
264         FInfo *fndrInfo;
265         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
266         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
267         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
268         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
269         numscreenshots++;
270         buf[26]++;
271         if(buf[26]==':'){
272         buf[26]='0';
273         buf[25]++;
274         if(buf[25]==':'){
275         buf[25]='0';
276         buf[24]++;
277         if(buf[24]==':'){
278         buf[24]='9';
279         buf[25]='9';
280         buf[26]='9';
281         }
282         }
283         }
284         }
285         }
286
287
288         // Get the GWorld
289         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
290         //assert(MAC_gWorld != NULL);
291
292         // Allocate memory for loading image
293         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
294         if (MAC_pixels == NULL) {
295         //UTIL_Error("Could not create Texture data.");
296         return;
297         }
298
299         // Get GWorld
300         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);      
301
302         // Make a picture Rectangle
303         MAC_picture_rectangle.left = 0;
304         MAC_picture_rectangle.right = screenwidth;
305         MAC_picture_rectangle.top = 0;
306         MAC_picture_rectangle.bottom = screenheight;    
307
308         // Create new offscreen GWorld
309         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
310         if (MAC_error_code)     {
311         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
312         delete MAC_pixels;
313         //UTIL_Error("Could not create offscreen GWorld. ");
314         return;
315
316         }
317
318         // Copy OpenGL Context to new GWorld
319         glReadBuffer(GL_FRONT); 
320         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
321
322         // Swizzle texture
323         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
324         unsigned char temp = MAC_pixels[byte+0];
325         MAC_pixels[byte+0] = MAC_pixels[byte+3];
326         MAC_pixels[byte+3] = MAC_pixels[byte+2];
327         MAC_pixels[byte+2] = MAC_pixels[byte+1];
328         MAC_pixels[byte+1] = temp;
329         }
330
331         // Flip the image  :(   This could probably be optimized
332         int vert;
333         int src_index;
334         int dst_index;
335         unsigned char temp;
336         for (int horz = 0; horz < screenwidth; ++horz)
337         for (vert = 0; vert < screenheight / 2; ++vert) {               
338         src_index = (screenwidth * vert + horz) * 4;
339         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
340
341         temp=MAC_pixels[src_index+0];
342         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
343         MAC_pixels[dst_index+0]=temp;
344
345         temp=MAC_pixels[src_index+1];
346         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
347         MAC_pixels[dst_index+1]=temp;
348
349         temp=MAC_pixels[src_index+2];
350         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
351         MAC_pixels[dst_index+2]=temp;
352
353         temp=MAC_pixels[src_index+3];
354         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
355         MAC_pixels[dst_index+3]=temp;
356         }
357
358
359
360         // Export the Gworld
361         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
362         if (MAC_error_code) {
363         //UTIL_Warning("Unable to export screenshot."); 
364         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
365         ::DisposeGWorld(MAC_offscreen_graphics_port);
366         delete MAC_pixels;
367         return;
368         }                                                                                               
369
370         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
371         if (MAC_error_code) {
372         ::CloseComponent(QT_exporter);
373         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
374         ::DisposeGWorld(MAC_offscreen_graphics_port);
375         delete MAC_pixels;
376         //UTIL_Warning("Unable to export screenshot.");
377         return;
378         }                                                               
379
380         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
381         if (MAC_error_code) {
382         ::CloseComponent(QT_exporter);
383         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
384         ::DisposeGWorld(MAC_offscreen_graphics_port);
385         delete MAC_pixels;
386         //UTIL_Warning("Unable to export screenshot.");
387         return;
388         }                                                       
389
390         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
391         if (MAC_error_code) {
392         ::CloseComponent(QT_exporter);
393         ::SetGWorld(MAC_currentPort, MAC_currentDevice);                        
394         ::DisposeGWorld(MAC_offscreen_graphics_port);
395         delete MAC_pixels;
396         //UTIL_Warning("Unable to export screenshot.");
397         return;
398         }                                               
399
400         ::CloseComponent(QT_exporter);
401         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
402         ::DisposeGWorld(MAC_offscreen_graphics_port);
403
404         delete MAC_pixels;*/
405 }
406
407
408
409 void    Game::SetUpLighting(){
410         if(environment==snowyenvironment){
411                 light.color[0]=.65;
412                 light.color[1]=.65;
413                 light.color[2]=.7;
414                 light.ambient[0]=.4;
415                 light.ambient[1]=.4;
416                 light.ambient[2]=.44;           
417         }
418         if(environment==desertenvironment){
419                 light.color[0]=.95;
420                 light.color[1]=.95;
421                 light.color[2]=.95;
422                 light.ambient[0]=.4;
423                 light.ambient[1]=.35;
424                 light.ambient[2]=.3;            
425         }
426
427         if(environment==grassyenvironment){
428                 light.color[0]=.95;
429                 light.color[1]=.95;
430                 light.color[2]=1;
431                 light.ambient[0]=.4;
432                 light.ambient[1]=.4;
433                 light.ambient[2]=.44;           
434         }
435         if(!skyboxtexture){
436                 light.color[0]=1;
437                 light.color[1]=1;
438                 light.color[2]=1;
439                 light.ambient[0]=.4;
440                 light.ambient[1]=.4;
441                 light.ambient[2]=.4;    
442         }
443         float average;
444         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
445         light.color[0]*=(skyboxlightr+average)/2;
446         light.color[1]*=(skyboxlightg+average)/2;
447         light.color[2]*=(skyboxlightb+average)/2;
448         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
449         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
450         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;   
451         /*
452         light.ambient[0]=0;
453         light.ambient[1]=0;
454         light.ambient[2]=0;     */
455 }
456
457 int Game::findPathDist(int start,int end){
458         int i,j,k,smallestcount,count,connected;
459         int last,last2,last3,last4;
460         int closest;
461
462         smallestcount=1000;
463         for(i=0;i<50;i++){
464                 count=0;
465                 last=start;
466                 last2=-1;
467                 last3=-1;
468                 last4=-1;
469                 while(last!=end&&count<30){
470                         closest=-1;
471                         for(j=0;j<numpathpoints;j++){
472                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
473                                 {
474                                         connected=0;
475                                         if(numpathpointconnect[j])
476                                                 for(k=0;k<numpathpointconnect[j];k++){
477                                                         if(pathpointconnect[j][k]==last)connected=1;
478                                                 }
479                                                 if(!connected)
480                                                         if(numpathpointconnect[last])
481                                                                 for(k=0;k<numpathpointconnect[last];k++){
482                                                                         if(pathpointconnect[last][k]==j)connected=1;
483                                                                 }
484                                                                 if(connected)
485                                                                         if(closest==-1||Random()%2==0){
486                                                                                 closest=j;
487                                                                         }
488                                 }
489                         }
490                         last4=last3;
491                         last3=last2;
492                         last2=last;
493                         last=closest;
494                         count++;
495                 }
496                 if(count<smallestcount)smallestcount=count;
497         }
498         return smallestcount;
499 }
500
501 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
502         static XYZ colpoint,colviewer,coltarget;
503         static float minx,minz,maxx,maxz,miny,maxy;
504         static int i;
505
506         //startpoint.y+=.7;
507         //endpoint.y+=.7;
508         //startpoint.y-=.1;
509         //endpoint.y-=.1;
510
511         minx=startpoint.x;
512         if(minx>endpoint.x)minx=endpoint.x;
513         miny=startpoint.y;
514         if(miny>endpoint.y)miny=endpoint.y;
515         minz=startpoint.z;
516         if(minz>endpoint.z)minz=endpoint.z;
517
518         maxx=startpoint.x;
519         if(maxx<endpoint.x)maxx=endpoint.x;
520         maxy=startpoint.y;
521         if(maxy<endpoint.y)maxy=endpoint.y;
522         maxz=startpoint.z;
523         if(maxz<endpoint.z)maxz=endpoint.z;
524
525         minx-=1;
526         miny-=1;
527         minz-=1;
528         maxx+=1;
529         maxy+=1;
530         maxz+=1;
531
532         for(i=0;i<objects.numobjects;i++){
533                 if(objects.position[i].x>minx-objects.model[i].boundingsphereradius&&objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&objects.position[i].y>miny-objects.model[i].boundingsphereradius&&objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&objects.position[i].z>minz-objects.model[i].boundingsphereradius&&objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
534                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
535                                 colviewer=startpoint;
536                                 coltarget=endpoint;
537                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;  
538                         }
539                 }
540         }
541
542         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
543
544         return -1;
545 }
546
547 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
548         static XYZ colpoint,colviewer,coltarget;
549         static float minx,minz,maxx,maxz,miny,maxy;
550         static int i;
551
552         //startpoint.y+=.7;
553         //endpoint.y+=.7;
554         //startpoint.y-=.1;
555         //endpoint.y-=.1;
556
557         minx=startpoint.x;
558         if(minx>endpoint.x)minx=endpoint.x;
559         miny=startpoint.y;
560         if(miny>endpoint.y)miny=endpoint.y;
561         minz=startpoint.z;
562         if(minz>endpoint.z)minz=endpoint.z;
563
564         maxx=startpoint.x;
565         if(maxx<endpoint.x)maxx=endpoint.x;
566         maxy=startpoint.y;
567         if(maxy<endpoint.y)maxy=endpoint.y;
568         maxz=startpoint.z;
569         if(maxz<endpoint.z)maxz=endpoint.z;
570
571         minx-=1;
572         miny-=1;
573         minz-=1;
574         maxx+=1;
575         maxy+=1;
576         maxz+=1;
577
578         if(what!=1000){
579                 if(objects.position[what].x>minx-objects.model[what].boundingsphereradius&&objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&objects.position[what].y>miny-objects.model[what].boundingsphereradius&&objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&objects.position[what].z>minz-objects.model[what].boundingsphereradius&&objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
580                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
581                                 colviewer=startpoint;
582                                 coltarget=endpoint;
583                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i; 
584                         }
585                 }
586         }
587
588         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
589
590         return -1;
591 }
592
593 void    Game::Setenvironment(int which)
594 {
595         LOGFUNC;
596
597         LOG(" Setting environment...");
598
599         float temptexdetail;
600         environment=which;
601 /*
602         FSOUND_SetPaused(channels[music1snow], TRUE);
603         FSOUND_SetPaused(channels[music1grass], TRUE);
604         FSOUND_SetPaused(channels[music1desert], TRUE);
605         FSOUND_SetPaused(channels[wind], TRUE);
606         FSOUND_SetPaused(channels[desertambient], TRUE);
607 */
608         FSOUND_SetPaused(channels[stream_music1snow], TRUE);
609         FSOUND_SetPaused(channels[stream_music1grass], TRUE);
610         FSOUND_SetPaused(channels[stream_music1desert], TRUE);
611         FSOUND_SetPaused(channels[stream_wind], TRUE);
612         FSOUND_SetPaused(channels[stream_desertambient], TRUE);
613
614
615         if(environment==snowyenvironment){
616                 windvector=0;
617                 windvector.z=3;
618                 if(ambientsound){
619                         //PlaySoundEx( wind, samp[wind], NULL, TRUE);
620                         PlayStreamEx(stream_wind, strm[stream_wind], 0, TRUE);
621                         FSOUND_SetPaused(channels[stream_wind], FALSE);
622                         FSOUND_SetVolume(channels[stream_wind], 256);
623                 }
624
625                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
626                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
627                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
628                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
629
630                 FSOUND_Sample_Free(samp[footstepsound]);
631                 FSOUND_Sample_Free(samp[footstepsound2]);
632                 FSOUND_Sample_Free(samp[footstepsound3]);
633                 FSOUND_Sample_Free(samp[footstepsound4]);
634                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
635                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
636                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
637                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
638                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
639                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
640                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
641                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
642
643                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
644
645                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
646
647                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
648
649
650
651
652                 temptexdetail=texdetail;
653                 if(texdetail>1)texdetail=4;
654                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
655                         ":Data:Textures:Skybox(snow):Left.jpg",
656                         ":Data:Textures:Skybox(snow):Back.jpg",
657                         ":Data:Textures:Skybox(snow):Right.jpg",
658                         ":Data:Textures:Skybox(snow):Up.jpg",
659                         ":Data:Textures:Skybox(snow):Down.jpg",
660                         ":Data:Textures:Skybox(snow):Cloud.jpg",
661                         ":Data:Textures:Skybox(snow):Reflect.jpg");
662
663
664
665
666                 texdetail=temptexdetail;
667         }
668         if(environment==desertenvironment){
669                 windvector=0;
670                 windvector.z=2;
671                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
672                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
673                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
674                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
675
676
677                 if(ambientsound){
678                         //PlaySoundEx( desertambient, samp[desertambient], NULL, TRUE);
679                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, TRUE);
680                         FSOUND_SetPaused(channels[stream_desertambient], FALSE);
681                         FSOUND_SetVolume(channels[stream_desertambient], 256);
682                 }
683
684                 FSOUND_Sample_Free(samp[footstepsound]);
685                 FSOUND_Sample_Free(samp[footstepsound2]);
686                 FSOUND_Sample_Free(samp[footstepsound3]);
687                 FSOUND_Sample_Free(samp[footstepsound4]);
688                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
689                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
690                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
691                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
692                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
693                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
694                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
695                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
696
697                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
698
699                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
700
701                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
702
703
704
705                 temptexdetail=texdetail;
706                 if(texdetail>1)texdetail=4;
707                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
708                         ":Data:Textures:Skybox(sand):Left.jpg",
709                         ":Data:Textures:Skybox(sand):Back.jpg",
710                         ":Data:Textures:Skybox(sand):Right.jpg",
711                         ":Data:Textures:Skybox(sand):Up.jpg",
712                         ":Data:Textures:Skybox(sand):Down.jpg",
713                         ":Data:Textures:Skybox(sand):Cloud.jpg",
714                         ":Data:Textures:Skybox(sand):Reflect.jpg");
715
716
717
718
719                 texdetail=temptexdetail;
720         }
721         if(environment==grassyenvironment){
722                 windvector=0;
723                 windvector.z=2;
724                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
725                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
726                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
727                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
728
729                 if(ambientsound){
730                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, TRUE);
731                         FSOUND_SetPaused(channels[stream_wind], FALSE);
732                         FSOUND_SetVolume(channels[stream_wind], 100);
733                 }
734
735                 FSOUND_Sample_Free(samp[footstepsound]);
736                 FSOUND_Sample_Free(samp[footstepsound2]);
737                 FSOUND_Sample_Free(samp[footstepsound3]);
738                 FSOUND_Sample_Free(samp[footstepsound4]);
739                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass1.ogg", FSOUND_HW3D, 0, 0);
740                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass2.ogg", FSOUND_HW3D, 0, 0);
741                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
742                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
743                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
744                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
745                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
746                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
747
748                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
749
750                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
751
752                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
753
754
755
756                 temptexdetail=texdetail;
757                 if(texdetail>1)texdetail=4;
758                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
759                         ":Data:Textures:Skybox(grass):Left.jpg",
760                         ":Data:Textures:Skybox(grass):Back.jpg",
761                         ":Data:Textures:Skybox(grass):Right.jpg",
762                         ":Data:Textures:Skybox(grass):Up.jpg",
763                         ":Data:Textures:Skybox(grass):Down.jpg",
764                         ":Data:Textures:Skybox(grass):Cloud.jpg",
765                         ":Data:Textures:Skybox(grass):Reflect.jpg");
766
767
768
769                 texdetail=temptexdetail;
770         }
771         temptexdetail=texdetail;
772         texdetail=1;
773         terrain.load(":Data:Textures:heightmap.png");
774
775         texdetail=temptexdetail;
776 }
777
778
779 void    Game::Loadlevel(int which){
780         stealthloading=0;
781
782         if(which==0)Loadlevel((char *)":Data:Maps:map1");
783         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
784         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
785         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
786         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
787         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
788         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
789         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
790         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
791         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
792         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
793         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
794         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
795         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
796         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
797         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
798         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
799         else Loadlevel((char *)":Data:Maps:mapsave");
800
801         whichlevel=which;
802 }
803
804 /*char * Game::MD5_string (unsigned char *string){
805 char temp[50];
806 char temp2[100];
807
808 strcpy(temp2,(const char *)string);
809 strcat((char *)temp2,(const char *)"Lugaru");                                   
810 sprintf (temp, "%d",strlen((char *)temp2));
811 strcat((char *)temp2,temp);                                     
812
813 MD5 context;
814 unsigned int len = strlen ( (char *)temp2);
815
816 context.update   ((unsigned char *)temp2, len);
817 context.finalize ();
818
819 return context.hex_digest();
820 }*/
821
822
823
824 void    Game::Loadlevel(char *name){
825         int i,j,k,l,m;
826         static int oldlevel;
827         int templength;
828         float lamefloat;
829         int lameint;
830
831         float headprop,legprop,armprop,bodyprop;
832
833         LOGFUNC;
834
835         LOG(std::string("Loading level...") + name);
836
837         if(!gameon)visibleloading=1;
838
839         if(stealthloading)visibleloading=0;
840
841         if(!stillloading)loadtime=0;
842         gamestarted=1;
843
844         numenvsounds=0;
845         //visibleloading=1;
846         if(tutoriallevel!=-1)tutoriallevel=0;
847         else tutoriallevel=1;
848
849         if(tutoriallevel==1)tutorialstage=0;
850         if(tutorialstage==0){
851                 tutorialstagetime=0;
852                 tutorialmaxtime=1;
853         }
854         loadingstuff=1;
855         if(!firstload){
856                 oldlevel=50;
857         }
858         FSOUND_SetPaused(channels[whooshsound], TRUE);
859         FSOUND_SetPaused(channels[stream_firesound], TRUE);
860
861         int mapvers;
862         FILE                    *tfile;
863         tfile=fopen( name, "rb" );
864         if(tfile)
865         {
866                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
867
868
869                 scoreadded=0;
870                 windialogue=0;
871
872                 hostiletime=0;
873
874                 won=0;
875
876                 //campaign=0;
877                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
878
879                 numdialogues=0;
880
881                 for(i=0;i<20;i++)
882                 {
883                         dialoguegonethrough[i]=0;
884                 }
885
886                 indialogue=-1;
887                 cameramode=0;
888
889                 damagedealt=0;
890                 damagetaken=0;
891
892                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
893
894                 if(difficulty!=2)minimap=1;
895                 else minimap=0;
896
897                 numhotspots=0;
898                 currenthotspot=-1;
899                 bonustime=1;
900
901                 skyboxtexture=1;
902                 skyboxr=1;
903                 skyboxg=1;
904                 skyboxb=1;
905
906                 freeze=0;
907                 winfreeze=0;
908
909                 for(i=0;i<100;i++)
910                 {
911                         bonusnum[i]=0;
912                 }
913
914                 numfalls=0;
915                 numflipfail=0;
916                 numseen=0;
917                 numstaffattack=0;
918                 numswordattack=0;
919                 numknifeattack=0;
920                 numunarmedattack=0;
921                 numescaped=0;
922                 numflipped=0;
923                 numwallflipped=0;
924                 numthrowkill=0;
925                 numafterkill=0;
926                 numreversals=0;
927                 numattacks=0;
928                 maxalarmed=0;
929                 numresponded=0;
930
931                 bonustotal=startbonustotal;
932                 bonus=0;
933                 gameon=1;
934                 changedelay=0;
935                 if(console)
936                 {
937                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
938                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
939                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
940                         freeze=0;
941                         console=0;
942                 }
943
944                 if(!stealthloading)
945                 {
946                         terrain.numdecals=0;
947                         sprites.numsprites=0;
948                         for(i=0;i<objects.numobjects;i++)
949                         {
950                                 objects.model[i].numdecals=0;
951                         }
952
953                         j=objects.numobjects;
954                         for(i=0;i<j;i++)
955                         {
956                                 objects.DeleteObject(0);
957                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
958                         }
959
960                         for(i=0;i<subdivision;i++)
961                         {
962                                 for(j=0;j<subdivision;j++)
963                                 {
964                                         terrain.patchobjectnum[i][j]=0;
965                                 }
966                         }
967                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
968                 }
969
970                 weapons.numweapons=0;
971
972                 funpackf(tfile, "Bi", &mapvers);
973                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
974                 else indemo=0;
975                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
976                 else maptype=mapkilleveryone;
977                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
978                 else hostile=1;
979                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
980                 else
981                 {
982                         viewdistance=100;
983                         fadestart=.6;
984                 }
985                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
986                 else
987                 {
988                         skyboxtexture=1;
989                         skyboxr=1;
990                         skyboxg=1;
991                         skyboxb=1;
992                 }
993                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
994                 else
995                 {
996                         skyboxlightr=skyboxr;
997                         skyboxlightg=skyboxg;
998                         skyboxlightb=skyboxb;
999                 }
1000                 if(!stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons);
1001                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1002                 player[0].originalcoords=player[0].coords;
1003                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1004                 {
1005                         for(j=0;j<player[0].num_weapons;j++)
1006                         {
1007                                 player[0].weaponids[j]=weapons.numweapons;
1008                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1009                                 weapons.owner[weapons.numweapons]=0;
1010                                 weapons.numweapons++;
1011                         }
1012                 }
1013
1014                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1015
1016                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1017                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1018                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1019                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1020
1021                 funpackf(tfile, "Bi", &player[0].numclothes);
1022
1023                 if(mapvers>=9)
1024                 {
1025                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1026                 }
1027                 else
1028                 {
1029                         player[0].whichskin=0;
1030                         player[0].creature=rabbittype;
1031                 }
1032
1033                 for(i=0;i<max_dialogues;i++)
1034                 {
1035                         for(j=0;j<max_dialoguelength;j++)
1036                         {
1037                                 for(k=0;k<128;k++)
1038                                 {
1039                                         dialoguetext[i][j][k]='\0';
1040                                 }
1041                                 for(k=0;k<64;k++)
1042                                 {
1043                                         dialoguename[i][j][k]='\0';
1044                                 }
1045                         }
1046                 }
1047
1048                 player[0].lastattack=-1;
1049                 player[0].lastattack2=-1;
1050                 player[0].lastattack3=-1;
1051
1052                 if(mapvers>=8)
1053                 {
1054                         funpackf(tfile, "Bi", &numdialogues);
1055                         if(numdialogues)
1056                         {
1057                                 for(k=0;k<numdialogues;k++)
1058                                 {
1059                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1060                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1061                                         for(l=0;l<10;l++)
1062                                         {
1063                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1064                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1065                                         }
1066                                         if(numdialogueboxes)
1067                                         {
1068                                                 for(l=0;l<numdialogueboxes[k];l++)
1069                                                 {
1070                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1071                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1072                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1073                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1074                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1075
1076                                                         bool doneread;
1077
1078                                                         funpackf(tfile, "Bi",&templength);
1079                                                         if(templength>128||templength<=0)templength=128;
1080                                                         for(m=0;m<templength;m++){
1081                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1082                                                                 if(dialoguetext[k][l][m]=='\0')break;
1083                                                         }
1084
1085                                                         funpackf(tfile, "Bi",&templength);
1086                                                         if(templength>64||templength<=0)templength=64;
1087                                                         for(m=0;m<templength;m++){
1088                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1089                                                                 if(dialoguename[k][l][m]=='\0'){
1090                                                                         break;  
1091                                                                 }
1092                                                         }
1093                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1094                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1095                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1096
1097                                                         for(m=0;m<10;m++)
1098                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1099
1100                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1101                                                 }
1102                                         }
1103                                 }
1104                         }
1105                 }
1106                 else numdialogues=0;
1107
1108                 if(player[0].numclothes)
1109                 {
1110                         for(k=0;k<player[0].numclothes;k++)
1111                         {
1112                                 funpackf(tfile, "Bi", &templength);
1113                                 for(l=0;l<templength;l++)
1114                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1115                                 player[0].clothes[k][templength]='\0';
1116                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);                                                                        
1117                         }
1118                 }
1119
1120                 funpackf(tfile, "Bi", &environment);
1121
1122                 funpackf(tfile, "Bi", &objects.numobjects);
1123                 if(objects.numobjects)
1124                 {
1125                         for(i=0;i<objects.numobjects;i++)
1126                         {
1127                                 funpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", &objects.type[i],&objects.rotation[i],&objects.rotation2[i], &objects.position[i].x, &objects.position[i].y, &objects.position[i].z,&objects.scale[i]);
1128                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1129                         }
1130                 }
1131
1132                 if(mapvers>=7)
1133                 {
1134                         funpackf(tfile, "Bi", &numhotspots);
1135                         if(numhotspots)
1136                         {
1137                                 for(i=0;i<numhotspots;i++)
1138                                 {
1139                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1140                                         funpackf(tfile, "Bi", &templength);
1141                                         if(templength)
1142                                                 for(l=0;l<templength;l++)
1143                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1144                                         hotspottext[i][templength]='\0';
1145                                         if(hotspottype[i]==-111)indemo=1;
1146                                 }
1147                         }
1148                 }
1149                 else numhotspots=0;
1150
1151                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1152
1153                 if(!stealthloading)
1154                 {
1155                         objects.center=0;
1156                         for(i=0;i<objects.numobjects;i++)
1157                         {
1158                                 objects.center+=objects.position[i];    
1159                         }
1160                         objects.center/=objects.numobjects;
1161
1162
1163                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1164
1165                         float maxdistance=0;
1166                         float tempdist;
1167                         int whichclosest;
1168                         for(i=0;i<objects.numobjects;i++)
1169                         {
1170                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1171                                 if(tempdist>maxdistance)
1172                                 {
1173                                         whichclosest=i;
1174                                         maxdistance=tempdist;
1175                                 }
1176                         }
1177                         objects.radius=fast_sqrt(maxdistance);
1178                 }                               
1179
1180                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1181                 //mapcenter=objects.center;
1182                 //mapradius=objects.radius;
1183
1184                 funpackf(tfile, "Bi", &numplayers);
1185                 int howmanyremoved=0;
1186                 bool removeanother=0;
1187                 if(numplayers>1&&numplayers<maxplayers)
1188                 {
1189                         for(i=1;i<numplayers;i++)
1190                         {
1191                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1192                                 removeanother=0;
1193
1194                                 funpackf(tfile, "Bi Bi Bf Bf Bf Bi",&player[i-howmanyremoved].whichskin,&player[i-howmanyremoved].creature, &player[i-howmanyremoved].coords.x,&player[i-howmanyremoved].coords.y,&player[i-howmanyremoved].coords.z,&player[i-howmanyremoved].num_weapons);
1195                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1196                                 else player[i-howmanyremoved].howactive=typeactive;
1197                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1198                                 else player[i-howmanyremoved].scale=-1;
1199                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1200                                 else player[i-howmanyremoved].immobile=0;
1201                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1202                                 else player[i-howmanyremoved].rotation=0;
1203                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1204                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1205                                         removeanother=1;
1206                                         howmanyremoved++;
1207                                 }
1208                                 if(!removeanother)
1209                                 {
1210                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1211                                         {
1212                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1213                                                 {
1214                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1215                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1216                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1217                                                         weapons.numweapons++;
1218                                                 }
1219                                         }
1220                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1221                                         //player[i-howmanyremoved].numwaypoints=10;
1222                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1223                                         {
1224                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1225                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1226                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1227                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1228                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1229                                         }
1230
1231                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1232                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1233
1234                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1235                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1236                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1237                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1238
1239                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1240                                         else
1241                                         {
1242                                                 headprop=1;
1243                                                 bodyprop=1;
1244                                                 armprop=1;
1245                                                 legprop=1;
1246                                         }
1247                                         if(player[i-howmanyremoved].creature==wolftype)
1248                                         {
1249                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1250                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1251                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1252                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1253                                         }
1254
1255                                         if(player[i-howmanyremoved].creature==rabbittype)
1256                                         {
1257                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1258                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1259                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1260                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1261                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1262                                         }
1263
1264                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1265                                         if(player[i-howmanyremoved].numclothes)
1266                                         {
1267                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1268                                                 {
1269                                                         int templength;
1270                                                         funpackf(tfile, "Bi", &templength);
1271                                                         for(l=0;l<templength;l++)
1272                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1273                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1274                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);                                                                   
1275                                                 }
1276                                         }
1277                                 }
1278                         }
1279                 }
1280                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1281
1282                 numplayers-=howmanyremoved;
1283                 funpackf(tfile, "Bi", &numpathpoints);
1284                 if(numpathpoints>30||numpathpoints<0)
1285                         numpathpoints=0;
1286                 if(numpathpoints)
1287                 {
1288                         for(j=0;j<numpathpoints;j++)
1289                         {
1290                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1291                                 for(k=0;k<numpathpointconnect[j];k++){
1292                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1293                                 }
1294                         }
1295                 }
1296                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1297
1298                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1299
1300                 SetUpLighting();
1301                 if(environment!=oldenvironment)Setenvironment(environment);
1302                 oldenvironment=environment;
1303
1304                 if(!stealthloading)
1305                 {
1306                         j=objects.numobjects;
1307                         objects.numobjects=0;
1308                         for(i=0;i<j;i++)
1309                         {
1310                                 //if(objects.type[i]!=spiketype)
1311                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1312                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1313                         }
1314
1315                         //if(skyboxtexture){
1316                         terrain.DoShadows();
1317                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1318                         objects.DoShadows();
1319                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1320                         /*}
1321                         else terrain.DoLighting();
1322                         */
1323                 }
1324
1325                 fclose(tfile);
1326
1327                 oldlevel=whichlevel;
1328
1329
1330                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1331                 for(i=0;i<numplayers;i++)
1332                 {
1333                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1334                         player[i].burnt=0;
1335                         player[i].bled=0;
1336                         player[i].onfire=0;
1337                         if(i==0||player[i].scale<0)player[i].scale=.2;
1338                         player[i].skeleton.free=0;
1339                         player[i].skeleton.id=i;
1340                         //if(Random()%2==0)player[i].creature=wolftype;
1341                         //else player[i].creature=rabbittype;
1342                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1343                         if(player[i].creature!=wolftype)player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",0);
1344                         else
1345                         {
1346                                 if(player[i].creature!=wolftype){
1347                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
1348                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1349                                 }
1350                                 if(player[i].creature==wolftype){
1351                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
1352                                 }
1353                         }
1354
1355
1356                         int texsize;
1357                         texsize=512*512*3/texdetail/texdetail;
1358                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1359                         //player[i].skeleton.skinText.resize(texsize);
1360
1361                         if(player[i].creature==rabbittype)
1362                         {
1363                                 if(player[i].whichskin==0){
1364                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1365                                 }
1366                                 else if(player[i].whichskin==1){
1367                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1368                                 }
1369                                 else if(player[i].whichskin==2){
1370                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1371                                 }
1372                                 else if(player[i].whichskin==3){
1373                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1374                                 }
1375                                 else if(player[i].whichskin==4){
1376                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1377                                 }
1378                                 else if(player[i].whichskin==5){
1379                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1380                                 }
1381                                 else if(player[i].whichskin==6){
1382                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1383                                 }
1384                                 else if(player[i].whichskin==7){
1385                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1386                                 }
1387                                 else if(player[i].whichskin==8){
1388                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1389                                 }
1390                                 else if(player[i].whichskin==9){
1391                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1392                                 }
1393                         }
1394                         if(player[i].creature==wolftype)
1395                         {
1396                                 //k=abs(Random()%3);
1397                                 if(player[i].whichskin==0){
1398                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1399                                 }
1400                                 else if(player[i].whichskin==1){
1401                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1402                                 }
1403                                 else if(player[i].whichskin==2){
1404                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1405                                 }
1406                         }
1407
1408                         if(player[i].numclothes)
1409                         {
1410                                 for(j=0;j<player[i].numclothes;j++)
1411                                 {
1412                                         tintr=player[i].clothestintr[j];
1413                                         tintg=player[i].clothestintg[j];
1414                                         tintb=player[i].clothestintb[j];
1415                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1416                                 }
1417                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1418                         }
1419
1420                         player[i].currentanimation=bounceidleanim;
1421                         player[i].targetanimation=bounceidleanim;
1422                         player[i].currentframe=0;
1423                         player[i].targetframe=1;
1424                         player[i].target=0;
1425                         player[i].speed=1+(float)(Random()%100)/1000;
1426                         if(difficulty==0)player[i].speed-=.2;
1427                         if(difficulty==1)player[i].speed-=.1;
1428
1429                         player[i].velocity=0;
1430                         player[i].oldcoords=player[i].coords;
1431                         player[i].realoldcoords=player[i].coords;
1432
1433                         player[i].id=i;
1434                         player[i].skeleton.id=i;
1435                         player[i].updatedelay=0;
1436                         player[i].normalsupdatedelay=0;
1437
1438                         player[i].aitype=passivetype;
1439                         player[i].aitarget=0;
1440                         player[i].madskills=0;
1441
1442                         if(i==0)
1443                         {
1444                                 player[i].proportionhead=1.2;
1445                                 player[i].proportionbody=1.05;
1446                                 player[i].proportionarms=1.00;
1447                                 player[i].proportionlegs=1.1;
1448                                 player[i].proportionlegs.y=1.05;
1449                         }
1450                         player[i].headless=0;
1451                         player[i].currentoffset=0;
1452                         player[i].targetoffset=0;
1453                         /*player[i].armorhead=1;
1454                         player[i].armorhigh=1;
1455                         player[i].armorlow=1;
1456                         player[i].protectionhead=1;
1457                         player[i].protectionhigh=1;
1458                         player[i].protectionlow=1;
1459                         player[i].metalhead=1;
1460                         player[i].metalhigh=1;
1461                         player[i].metallow=1;
1462                         player[i].power=1;
1463                         player[i].speedmult=1;*/
1464
1465                         player[i].damagetolerance=200;
1466
1467                         if(player[i].creature==wolftype)
1468                         {
1469                                 /*player[i].proportionhead=1.1;
1470                                 player[i].proportionbody=1.1;
1471                                 player[i].proportionarms=1.1;
1472                                 player[i].proportionlegs=1.1;
1473                                 player[i].proportionlegs.y=1.1;*/
1474                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1475
1476                                 player[i].damagetolerance=300;
1477                         }                               
1478
1479                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1480                         if(cellophane)
1481                         {
1482                                 player[i].proportionhead.z=0;
1483                                 player[i].proportionbody.z=0;
1484                                 player[i].proportionarms.z=0;
1485                                 player[i].proportionlegs.z=0;
1486                         }
1487
1488                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1489
1490                         player[i].headmorphness=0;
1491                         player[i].targetheadmorphness=1;
1492                         player[i].headmorphstart=0;
1493                         player[i].headmorphend=0;
1494
1495                         player[i].pausetime=0;
1496
1497                         player[i].dead=0;
1498                         player[i].jumppower=5;
1499                         player[i].damage=0;
1500                         player[i].permanentdamage=0;
1501                         player[i].superpermanentdamage=0;
1502
1503                         player[i].forwardkeydown=0;
1504                         player[i].leftkeydown=0;
1505                         player[i].backkeydown=0;
1506                         player[i].rightkeydown=0;
1507                         player[i].jumpkeydown=0;
1508                         player[i].crouchkeydown=0;
1509                         player[i].throwkeydown=0;
1510
1511                         player[i].collided=-10;
1512                         player[i].loaded=1;
1513                         player[i].bloodloss=0;
1514                         player[i].weaponactive=-1;
1515                         player[i].weaponstuck=-1;
1516                         player[i].bleeding=0;
1517                         player[i].deathbleeding=0;
1518                         player[i].stunned=0;
1519                         player[i].hasvictim=0;
1520                         player[i].wentforweapon=0;
1521                 }
1522
1523                 player[0].aitype=playercontrolled;
1524                 player[0].weaponactive=-1;
1525
1526                 if(difficulty==1)
1527                 {
1528                         //player[0].speedmult=1/.9;
1529                         player[0].power=1/.9;
1530                 }
1531
1532                 if(difficulty==0)
1533                 {
1534                         //player[0].speedmult=1/.8;
1535                         player[0].power=1/.8;
1536                 }
1537
1538                 //player[0].weaponstuck=1;
1539
1540                 if(difficulty==1)player[0].damagetolerance=250;
1541                 if(difficulty==0)player[0].damagetolerance=300;
1542                 if(difficulty==0)player[0].armorhead*=1.5;
1543                 if(difficulty==0)player[0].armorhigh*=1.5;
1544                 if(difficulty==0)player[0].armorlow*=1.5;
1545                 cameraloc=player[0].coords;
1546                 cameraloc.y+=5;
1547                 rotation=player[0].rotation;
1548
1549                 hawkcoords=player[0].coords;
1550                 hawkcoords.y+=30;
1551
1552                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1553                 //weapons.numweapons=numplayers;
1554                 for(i=0;i<weapons.numweapons;i++)
1555                 {
1556                         weapons.bloody[i]=0;
1557                         weapons.blooddrip[i]=0;
1558                         weapons.blooddripdelay[i]=0;
1559                         weapons.onfire[i]=0;
1560                         weapons.flamedelay[i]=0;
1561                         weapons.damage[i]=0;
1562                         //weapons.type[i]=sword;
1563                         if(weapons.type[i]==sword){
1564                                 weapons.mass[i]=1.5;
1565                                 weapons.tipmass[i]=1;
1566                                 weapons.length[i]=.8;
1567                         }
1568                         if(weapons.type[i]==staff){
1569                                 weapons.mass[i]=2;
1570                                 weapons.tipmass[i]=1;
1571                                 weapons.length[i]=1.5;
1572                         }
1573                         if(weapons.type[i]==knife){
1574                                 weapons.mass[i]=1;
1575                                 weapons.tipmass[i]=1.2;
1576                                 weapons.length[i]=.25;
1577                         }
1578                         weapons.position[i]=-1000;
1579                         weapons.tippoint[i]=-1000;
1580                 }
1581
1582 /*              for(i=0;i<32;i++){
1583                         //if(i<16||i>20)                                
1584                         FSOUND_StopSound(i);
1585                 }
1586 */
1587                 LOG("Starting background music...");
1588
1589                 FSOUND_StopSound(FSOUND_ALL);
1590                 if(environment==snowyenvironment)
1591                 {
1592                         if(ambientsound)
1593                         {
1594                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
1595                                 FSOUND_SetPaused(channels[stream_wind], FALSE);
1596                                 FSOUND_SetVolume(channels[stream_wind], 256);
1597                         }
1598                 }
1599                 else if(environment==desertenvironment)
1600                 {
1601                         if(ambientsound)
1602                         {
1603                                 //PlaySoundEx(desertambient,
1604                                 //      samp[desertambient], NULL, TRUE);
1605                                 PlayStreamEx(stream_desertambient,
1606                                         strm[stream_desertambient], NULL, TRUE);
1607                                 FSOUND_SetPaused(channels[stream_desertambient], FALSE);
1608                                 FSOUND_SetVolume(channels[stream_desertambient], 256);
1609                         }
1610                 }
1611                 else if(environment==grassyenvironment)
1612                 {
1613                         if(ambientsound)
1614                         {
1615                                 //PlaySoundEx(wind, samp[wind], NULL, TRUE);
1616                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
1617                                 FSOUND_SetPaused(channels[stream_wind], FALSE);
1618                                 FSOUND_SetVolume(channels[stream_wind], 100);
1619                         }
1620                 }
1621                 oldmusicvolume[0]=0;
1622                 oldmusicvolume[1]=0;
1623                 oldmusicvolume[2]=0;
1624                 oldmusicvolume[3]=0;
1625
1626
1627                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1628                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1629                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1630                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1631                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1632                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1633                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1634                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1635                 */
1636
1637                 if(!firstload)
1638                 {
1639                         firstload=1;
1640                 }
1641         }
1642         leveltime=0;
1643         loadingstuff=0;
1644         visibleloading=0;
1645 }
1646
1647 void    Game::Tick()
1648 {
1649         static int i,k,j,l,m;
1650         static XYZ facing,flatfacing,absflatfacing;
1651         static XYZ rotatetarget;
1652         static bool oldkey;
1653         static float oldtargetrotation;
1654         static int target, numgood;
1655         static XYZ tempcoords1,tempcoords2;
1656         static XYZ test;
1657         static XYZ test2;
1658         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1659         static int whichhit;
1660         static bool donesomething;
1661         static bool oldjumpkeydown;
1662
1663         int templength;
1664
1665         float headprop,bodyprop,armprop,legprop;
1666
1667         if(newnetmessages){
1668                 newnetmessages=0;
1669                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
1670                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
1671                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
1672
1673                 for(k=14;k>=2;k--){
1674                         for(j=0;j<255;j++){
1675                                 consoletext[k][j]=consoletext[k-1][j];
1676                         }
1677                         consolechars[k]=consolechars[k-1];
1678                 }
1679                 for(k=14;k>=2;k--){
1680                         for(j=0;j<255;j++){
1681                                 displaytext[k][j]=displaytext[k-1][j];
1682                         }
1683                         displaychars[k]=displaychars[k-1];
1684                         displaytime[k]=displaytime[k-1];
1685                 }
1686                 for(j=0;j<255;j++){
1687                         consoletext[1][j]=' ';
1688                         displaytext[1][j]=' ';
1689                 }
1690                 sprintf (consoletext[1], netmessages);
1691                 sprintf (displaytext[1], netmessages);
1692                 consolechars[1]=255;
1693                 displaychars[1]=255;
1694                 displaytime[1]=0;
1695         }
1696
1697         for(i=0;i<15;i++){
1698                 displaytime[i]+=multiplier;
1699         }
1700
1701         static unsigned char    theKeyMap[16];
1702         GetKeys( theKeyMap );
1703
1704         keyboardfrozen=0;
1705
1706
1707         static bool mainmenutogglekeydown;
1708         if(!console){
1709                 if(mainmenu&&endgame==1)mainmenu=10;
1710                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1711                         for(j=0;j<255;j++){
1712                                 displaytext[0][j]=' ';
1713                         }
1714                         displaychars[0]=0;
1715                         displayselected=0;
1716                         entername=0;
1717                         mainmenutogglekeydown=1;
1718                 }
1719                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||(mainmenu==12&&!tryquit)||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17||mainmenu==10)){
1720                         selected=-1;
1721                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1722                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1723                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1724                                 else if(mainmenu==0&&winfreeze){
1725                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1726                                         stealthloading=1;
1727                                         else stealthloading=0;
1728
1729                                         if(!stealthloading){
1730                                         float gLoc[3]={0,0,0};
1731                                         float vel[3]={0,0,0};
1732                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
1733                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
1734                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1735                                         FSOUND_SetVolume(channels[firestartsound], 256);
1736                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
1737                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1738
1739                                         flashr=1;
1740                                         flashg=0;
1741                                         flashb=0;
1742                                         flashamount=1;
1743                                         flashdelay=1;
1744                                         }
1745
1746                                         startbonustotal=0;
1747
1748                                         for(i=0;i<campaignnumlevels;i++){
1749                                         levelvisible[i]=0;
1750                                         levelhighlight[i]=0;
1751                                         }
1752
1753                                         levelorder[0]=0;
1754                                         levelvisible[0]=1;
1755                                         if(accountcampaignchoicesmade[accountactive])
1756                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1757                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1758                                         levelvisible[levelorder[i+1]]=1;
1759                                         }
1760                                         int whichlevelstart;
1761                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1762                                         if(whichlevelstart<0){
1763                                         campaignchoicenum=1;
1764                                         campaignchoicewhich[0]=0;
1765                                         }
1766                                         else
1767                                         {
1768                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1769                                         if(campaignchoicenum)
1770                                         for(i=0;i<campaignchoicenum;i++){
1771                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1772                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1773                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1774                                         }
1775                                         }
1776
1777                                         loading=2;
1778                                         loadtime=0;
1779                                         targetlevel=7;
1780                                         if(firstload)TickOnceAfter();
1781                                         if(!firstload)LoadStuff();
1782                                         //else {
1783                                         for(i=0;i<255;i++){
1784                                         mapname[i]='\0';
1785                                         }
1786                                         mapname[0]=':';
1787                                         mapname[1]='D';
1788                                         mapname[2]='a';
1789                                         mapname[3]='t';
1790                                         mapname[4]='a';
1791                                         mapname[5]=':';
1792                                         mapname[6]='M';
1793                                         mapname[7]='a';
1794                                         mapname[8]='p';
1795                                         mapname[9]='s';
1796                                         mapname[10]=':';
1797
1798                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1799                                         //accountcampaignchoicesmade[accountactive]++;
1800
1801
1802                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1803                                         whichchoice=0;
1804                                         visibleloading=1;
1805                                         stillloading=1;
1806                                         Loadlevel(mapname);
1807                                         campaign=1;
1808                                         mainmenu=0;
1809                                         gameon=1;
1810                                         FSOUND_SetPaused(channels[music3], TRUE);
1811
1812                                         stealthloading=0;*/
1813                                 }
1814                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1815                                 if(mainmenu&&musictoggle){
1816                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1817                                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
1818                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
1819                                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
1820                                                 FSOUND_SetVolume(channels[stream_music3], 256);
1821                                                 FSOUND_SetPaused(channels[music1], TRUE);
1822                                         }
1823                                 }
1824                                 if(!mainmenu){
1825                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
1826                                         FSOUND_SetPaused(channels[music1], FALSE);
1827                                 }
1828                         }
1829                         if(mainmenu==3){
1830                                 float gLoc[3]={0,0,0};
1831                                 float vel[3]={0,0,0};
1832                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1833                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1834                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1835                                 FSOUND_SetVolume(channels[fireendsound], 256);
1836                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1837                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1838
1839                                 flashr=1;
1840                                 flashg=0;
1841                                 flashb=0;
1842                                 flashamount=1;
1843                                 flashdelay=1;
1844
1845                                 if(newdetail>2)newdetail=detail;
1846                                 if(newdetail<0)newdetail=detail;
1847                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
1848                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1849                                 if(newscreenheight>3000)newscreenheight=screenheight;
1850                                 if(newscreenheight<0)newscreenheight=screenheight;
1851
1852                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
1853                                 opstream << "Screenwidth:\n";
1854                                 opstream << newscreenwidth;
1855                                 opstream << "\nScreenheight:\n";
1856                                 opstream << newscreenheight;
1857                                 opstream << "\nMouse sensitivity:\n";
1858                                 opstream << usermousesensitivity;
1859                                 opstream << "\nBlur(0,1):\n";
1860                                 opstream << ismotionblur;
1861                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1862                                 opstream << newdetail;
1863                                 opstream << "\nFloating jump:\n";
1864                                 opstream << floatjump;
1865                                 opstream << "\nMouse jump:\n";
1866                                 opstream << mousejump;
1867                                 opstream << "\nAmbient sound:\n";
1868                                 opstream << ambientsound;
1869                                 opstream << "\nBlood (0,1,2):\n";
1870                                 opstream << bloodtoggle;
1871                                 opstream << "\nAuto slomo:\n";
1872                                 opstream << autoslomo;
1873                                 opstream << "\nFoliage:\n";
1874                                 opstream << foliage;
1875                                 opstream << "\nMusic:\n";
1876                                 opstream << musictoggle;
1877                                 opstream << "\nTrilinear:\n";
1878                                 opstream << trilinear;
1879                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1880                                 opstream << decals;
1881                                 opstream << "\nInvert mouse:\n";
1882                                 opstream << invertmouse;
1883                                 opstream << "\nGamespeed:\n";
1884                                 if(oldgamespeed==0)oldgamespeed=1;
1885                                 opstream << oldgamespeed;
1886                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1887                                 opstream << difficulty;
1888                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1889                                 opstream << damageeffects;
1890                                 opstream << "\nText:\n";
1891                                 opstream << texttoggle;
1892                                 opstream << "\nDebug:\n";
1893                                 opstream << debugmode;
1894                                 opstream << "\nVBL Sync:\n";
1895                                 opstream << vblsync;
1896                                 opstream << "\nShow Points:\n";
1897                                 opstream << showpoints;
1898                                 opstream << "\nAlways Blur:\n";
1899                                 opstream << alwaysblur;
1900                                 opstream << "\nImmediate mode (turn on on G5):\n";
1901                                 opstream << immediate;
1902                                 opstream << "\nVelocity blur:\n";
1903                                 opstream << velocityblur;
1904                             opstream << "\nVolume:\n";
1905                         opstream << volume;
1906                                 opstream << "\nForward key:\n";
1907                                 opstream << KeyToChar(forwardkey);
1908                                 opstream << "\nBack key:\n";
1909                                 opstream << KeyToChar(backkey);
1910                                 opstream << "\nLeft key:\n";
1911                                 opstream << KeyToChar(leftkey);
1912                                 opstream << "\nRight key:\n";
1913                                 opstream << KeyToChar(rightkey);
1914                                 opstream << "\nJump key:\n";
1915                                 opstream << KeyToChar(jumpkey);
1916                                 opstream << "\nCrouch key:\n";
1917                                 opstream << KeyToChar(crouchkey);
1918                                 opstream << "\nDraw key:\n";
1919                                 opstream << KeyToChar(drawkey);
1920                                 opstream << "\nThrow key:\n";
1921                                 opstream << KeyToChar(throwkey);
1922                                 opstream << "\nAttack key:\n";
1923                                 opstream << KeyToChar(attackkey);
1924                                 opstream << "\nChat key:\n";
1925                                 opstream << KeyToChar(chatkey);
1926                                 opstream.close();
1927                         }       
1928                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==10||mainmenu==11||mainmenu==100){
1929                                 float gLoc[3]={0,0,0};
1930                                 float vel[3]={0,0,0};
1931                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1932                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1933                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1934                                 FSOUND_SetVolume(channels[fireendsound], 256);
1935                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1936                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1937
1938                                 flashr=1;
1939                                 flashg=0;
1940                                 flashb=0;
1941                                 flashamount=1;
1942                                 flashdelay=1;
1943                         }       
1944                         if(mainmenu==3&&gameon)mainmenu=2;
1945                         if(mainmenu==3&&!gameon)mainmenu=1;
1946                         if(mainmenu==5&&gameon)mainmenu=2;
1947                         if(mainmenu==5&&!gameon)mainmenu=1;
1948                         if(mainmenu==4)mainmenu=3;
1949                         if(mainmenu==6)mainmenu=5;
1950                         if(mainmenu==7)mainmenu=1;
1951                         if(mainmenu==9)mainmenu=5;
1952                         if(mainmenu==11)mainmenu=5;
1953                         if(mainmenu==12)mainmenu=5;
1954                         if(mainmenu==13)mainmenu=12;
1955                         if(mainmenu==14)mainmenu=13;
1956                         if(mainmenu==10)mainmenu=5;
1957                         if(mainmenu==100){
1958                                 mainmenu=5;
1959                                 gameon=0;
1960                                 winfreeze=0;
1961                         }
1962                         mainmenutogglekeydown=1;
1963                 }
1964                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1965                         mainmenutogglekeydown=0;
1966                 }
1967         }
1968
1969         /*static bool minimaptogglekeydown;
1970         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1971         minimap=1-minimap;
1972         minimaptogglekeydown=1;
1973         }
1974         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1975         minimaptogglekeydown=0;
1976         }
1977         */
1978
1979         static bool minimaptogglekeydown;
1980         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
1981                 if(tutorialstage!=51)
1982                         tutorialstagetime=tutorialmaxtime;
1983                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
1984                 FSOUND_SetVolume(channels[consolefailsound], 128);
1985                 FSOUND_SetPaused(channels[consolefailsound], FALSE);
1986                 minimaptogglekeydown=1;
1987         }
1988         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1989                 minimaptogglekeydown=0;
1990         }
1991
1992         if(mainmenu){
1993                 //menu buttons
1994                 if(mainmenu==1||mainmenu==2){
1995                         if(Button()&&!oldbutton&&selected==1){
1996                                 if(!gameon){
1997                                         float gLoc[3]={0,0,0};
1998                                         float vel[3]={0,0,0};
1999                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2000                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2001                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2002                                         FSOUND_SetVolume(channels[firestartsound], 256);
2003                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
2004                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2005
2006                                         flashr=1;
2007                                         flashg=0;
2008                                         flashb=0;
2009                                         flashamount=1;
2010                                         flashdelay=1;
2011
2012                                         //new game
2013                                         if(accountactive!=-1)mainmenu=5;
2014                                         else mainmenu=7;
2015                                         /*
2016                                         startbonustotal=0;
2017
2018                                         loading=2;
2019                                         loadtime=0;
2020                                         if(firstload)TickOnceAfter();
2021                                         if(!firstload)LoadStuff();
2022                                         else {
2023                                         Loadlevel(0);
2024                                         }
2025                                         mainmenu=0;
2026                                         gameon=1;
2027                                         FSOUND_SetPaused(channels[music3], TRUE);       */                      
2028                                 }
2029                                 else
2030                                 {
2031                                         //resume
2032                                         mainmenu=0;
2033                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
2034                                         FSOUND_SetPaused(channels[music1], FALSE);
2035                                 }
2036                         }
2037
2038                         if(Button()&&!oldbutton&&selected==2){
2039                                 float gLoc[3]={0,0,0};
2040                                 float vel[3]={0,0,0};
2041                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2042                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2043                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2044                                 FSOUND_SetVolume(channels[firestartsound], 256);
2045                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2046                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2047
2048                                 flashr=1;
2049                                 flashg=0;
2050                                 flashb=0;
2051                                 flashamount=1;
2052                                 flashdelay=1;
2053
2054                                 //options
2055
2056                                 mainmenu=3;                     
2057
2058                                 if(newdetail>2)newdetail=detail;
2059                                 if(newdetail<0)newdetail=detail;
2060                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2061                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2062                                 if(newscreenheight>3000)newscreenheight=screenheight;
2063                                 if(newscreenheight<0)newscreenheight=screenheight;      
2064                         }
2065
2066                         if(Button()&&!oldbutton&&selected==3){
2067                                 float gLoc[3]={0,0,0};
2068                                 float vel[3]={0,0,0};
2069                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2070                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2071                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2072                                 FSOUND_SetVolume(channels[fireendsound], 256);
2073                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2074                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2075
2076                                 flashr=1;
2077                                 flashg=0;
2078                                 flashb=0;
2079                                 flashamount=1;
2080                                 flashdelay=1;
2081
2082                                 if(!gameon){
2083                                         //quit
2084                                         tryquit=1;
2085                                         if(registered)FSOUND_SetPaused(channels[stream_music3], TRUE);
2086                                 }
2087                                 else{
2088                                         //end game
2089                                         gameon=0;
2090                                         mainmenu=1;
2091                                 }
2092                         }
2093                         if(Button())oldbutton=1;
2094                         else oldbutton=0;
2095                 }
2096
2097                 if(mainmenu==3){
2098                         if(Button()&&!oldbutton&&selected!=-1){
2099                                 float gLoc[3]={0,0,0};
2100                                 float vel[3]={0,0,0};
2101                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2102                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2103                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2104                                 FSOUND_SetVolume(channels[firestartsound], 256);
2105                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2106                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2107                         }
2108                         if(Button()&&!oldbutton&&selected==0){
2109                                 int whichres;
2110                                 whichres=-1;
2111                                 if(newscreenwidth==640&&newscreenheight==480)whichres=0;
2112                                 if(newscreenwidth==800&&newscreenheight==600)whichres=1;
2113                                 if(newscreenwidth==1024&&newscreenheight==768)whichres=2;
2114                                 if(newscreenwidth==1280&&newscreenheight==1024)whichres=3;
2115                                 if(newscreenwidth==1600&&newscreenheight==1200)whichres=4;
2116                                 if(newscreenwidth==840&&newscreenheight==524)whichres=5;
2117                                 if(newscreenwidth==1024&&newscreenheight==640)whichres=6;
2118                                 if(newscreenwidth==1344&&newscreenheight==840)whichres=7;
2119
2120                                 if(whichres==-1||whichres==7){
2121                                         newscreenwidth=640;
2122                                         newscreenheight=480;
2123                                 }
2124                                 if(whichres==0){
2125                                         newscreenwidth=800;
2126                                         newscreenheight=600;
2127                                 }
2128                                 if(whichres==1){
2129                                         newscreenwidth=1024;
2130                                         newscreenheight=768;
2131                                 }
2132                                 if(whichres==2){
2133                                         newscreenwidth=1280;
2134                                         newscreenheight=1024;
2135                                 }
2136                                 if(whichres==3){
2137                                         newscreenwidth=1600;
2138                                         newscreenheight=1200;
2139                                 }
2140                                 if(whichres==4){
2141                                         newscreenwidth=840;
2142                                         newscreenheight=524;
2143                                 }
2144                                 if(whichres==5){
2145                                         newscreenwidth=1024;
2146                                         newscreenheight=640;
2147                                 }
2148                                 if(whichres==6){
2149                                         newscreenwidth=1344;
2150                                         newscreenheight=840;
2151                                 }
2152                         }
2153                         if(Button()&&!oldbutton&&selected==1){
2154                                 newdetail++;
2155                                 if(newdetail>2)newdetail=0;
2156                         }
2157                         if(Button()&&!oldbutton&&selected==2){
2158                                 bloodtoggle++;
2159                                 if(bloodtoggle>2)bloodtoggle=0;
2160                         }
2161                         if(Button()&&!oldbutton&&selected==3){
2162                                 difficulty++;
2163                                 if(difficulty>2)difficulty=0;
2164                         }
2165                         if(Button()&&!oldbutton&&selected==4){
2166                                 ismotionblur=1-ismotionblur;
2167                         }
2168                         if(Button()&&!oldbutton&&selected==5){
2169                                 decals=1-decals;
2170                         }
2171                         if(Button()&&!oldbutton&&selected==6){
2172                                 musictoggle=1-musictoggle;
2173
2174                                 if(!musictoggle){
2175                                         FSOUND_SetPaused(channels[music1], TRUE);
2176                                         FSOUND_SetPaused(channels[stream_music2], TRUE);
2177                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
2178
2179                                         for(i=0;i<4;i++){
2180                                                 oldmusicvolume[i]=0;
2181                                                 musicvolume[i]=0;
2182                                         }
2183                                 }
2184
2185                                 if(musictoggle){
2186                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
2187                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
2188                                         FSOUND_SetVolume(channels[stream_music3], 256);                         
2189                                 }
2190                         }
2191                         if(Button()&&!oldbutton&&selected==9){
2192                                 invertmouse=1-invertmouse;
2193                         }
2194                         if(Button()&&!oldbutton&&selected==10){
2195                                 usermousesensitivity+=.2;
2196                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2197                         }
2198                         if(Button()&&!oldbutton&&selected==11){
2199                                 volume+=.1f;
2200                                 if(volume>1.0001f)volume=0;
2201                                 FSOUND_SetSFXMasterVolume((int)(volume*255));
2202                         }
2203                         if(Button()&&!oldbutton&&selected==7){
2204                                 /*float gLoc[3]={0,0,0};
2205                                 float vel[3]={0,0,0};
2206                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2207                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2208                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2209                                 FSOUND_SetVolume(channels[firestartsound], 256);
2210                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2211                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2212                                 */
2213                                 flashr=1;
2214                                 flashg=0;
2215                                 flashb=0;
2216                                 flashamount=1;
2217                                 flashdelay=1;
2218
2219                                 //options
2220
2221                                 mainmenu=4;             
2222                                 keyselect=-1;
2223                         }
2224                         if(Button()&&!oldbutton&&selected==8){
2225                                 float gLoc[3]={0,0,0};
2226                                 float vel[3]={0,0,0};
2227                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2228                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2229                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2230                                 FSOUND_SetVolume(channels[fireendsound], 256);
2231                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2232                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2233
2234                                 flashr=1;
2235                                 flashg=0;
2236                                 flashb=0;
2237                                 flashamount=1;
2238                                 flashdelay=1;
2239
2240                                 if(newdetail>2)newdetail=detail;
2241                                 if(newdetail<0)newdetail=detail;
2242                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2243                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2244                                 if(newscreenheight>3000)newscreenheight=screenheight;
2245                                 if(newscreenheight<0)newscreenheight=screenheight;
2246
2247
2248                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2249                                 opstream << "Screenwidth:\n";
2250                                 opstream << newscreenwidth;
2251                                 opstream << "\nScreenheight:\n";
2252                                 opstream << newscreenheight;
2253                                 opstream << "\nMouse sensitivity:\n";
2254                                 opstream << usermousesensitivity;
2255                                 opstream << "\nBlur(0,1):\n";
2256                                 opstream << ismotionblur;
2257                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2258                                 opstream << newdetail;
2259                                 opstream << "\nFloating jump:\n";
2260                                 opstream << floatjump;
2261                                 opstream << "\nMouse jump:\n";
2262                                 opstream << mousejump;
2263                                 opstream << "\nAmbient sound:\n";
2264                                 opstream << ambientsound;
2265                                 opstream << "\nBlood (0,1,2):\n";
2266                                 opstream << bloodtoggle;
2267                                 opstream << "\nAuto slomo:\n";
2268                                 opstream << autoslomo;
2269                                 opstream << "\nFoliage:\n";
2270                                 opstream << foliage;
2271                                 opstream << "\nMusic:\n";
2272                                 opstream << musictoggle;
2273                                 opstream << "\nTrilinear:\n";
2274                                 opstream << trilinear;
2275                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2276                                 opstream << decals;
2277                                 opstream << "\nInvert mouse:\n";
2278                                 opstream << invertmouse;
2279                                 opstream << "\nGamespeed:\n";
2280                                 if(oldgamespeed==0)oldgamespeed=1;
2281                                 opstream << oldgamespeed;
2282                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2283                                 opstream << difficulty;
2284                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2285                                 opstream << damageeffects;
2286                                 opstream << "\nText:\n";
2287                                 opstream << texttoggle;
2288                                 opstream << "\nDebug:\n";
2289                                 opstream << debugmode;
2290                                 opstream << "\nVBL Sync:\n";
2291                                 opstream << vblsync;
2292                                 opstream << "\nShow Points:\n";
2293                                 opstream << showpoints;
2294                                 opstream << "\nAlways Blur:\n";
2295                                 opstream << alwaysblur;
2296                                 opstream << "\nImmediate mode (turn on on G5):\n";
2297                                 opstream << immediate;
2298                                 opstream << "\nVelocity blur:\n";
2299                                 opstream << velocityblur;
2300                             opstream << "\nVolume:\n";
2301                         opstream << volume;
2302                                 opstream << "\nForward key:\n";
2303                                 opstream << KeyToChar(forwardkey);
2304                                 opstream << "\nBack key:\n";
2305                                 opstream << KeyToChar(backkey);
2306                                 opstream << "\nLeft key:\n";
2307                                 opstream << KeyToChar(leftkey);
2308                                 opstream << "\nRight key:\n";
2309                                 opstream << KeyToChar(rightkey);
2310                                 opstream << "\nJump key:\n";
2311                                 opstream << KeyToChar(jumpkey);
2312                                 opstream << "\nCrouch key:\n";
2313                                 opstream << KeyToChar(crouchkey);
2314                                 opstream << "\nDraw key:\n";
2315                                 opstream << KeyToChar(drawkey);
2316                                 opstream << "\nThrow key:\n";
2317                                 opstream << KeyToChar(throwkey);
2318                                 opstream << "\nAttack key:\n";
2319                                 opstream << KeyToChar(attackkey);
2320                                 opstream << "\nChat key:\n";
2321                                 opstream << KeyToChar(chatkey);
2322                                 opstream.close();
2323
2324                                 if(mainmenu==3&&gameon)mainmenu=2;
2325                                 if(mainmenu==3&&!gameon)mainmenu=1;
2326                         }
2327                         if(Button())oldbutton=1;
2328                         else oldbutton=0;
2329                 }
2330                 if(mainmenu==4){
2331                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2332                                 float gLoc[3]={0,0,0};
2333                                 float vel[3]={0,0,0};
2334                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2335                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2336                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2337                                 FSOUND_SetVolume(channels[firestartsound], 256);
2338                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2339                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2340                         }
2341                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2342                                 keyselect=selected;
2343                                 oldbuttons[0]=1;
2344                                 oldbuttons[1]=1;
2345                                 oldbuttons[2]=1;
2346                         }
2347                         if(keyselect!=-1){
2348                                 for(i=0;i<3;i++)
2349                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2350                                 for(i=0;i<140;i++){
2351                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2352                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2353                                                         float gLoc[3]={0,0,0};
2354                                                         float vel[3]={0,0,0};
2355                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2356                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2357                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2358                                                         FSOUND_SetVolume(channels[fireendsound], 256);
2359                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
2360                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2361
2362                                                         int keynum;
2363                                                         keynum=i;
2364                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2365                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2366
2367
2368
2369                                                         if(keyselect==0)forwardkey=keynum;
2370                                                         if(keyselect==1)backkey=keynum;
2371                                                         if(keyselect==2)leftkey=keynum;
2372                                                         if(keyselect==3)rightkey=keynum;
2373                                                         if(keyselect==4)crouchkey=keynum;
2374                                                         if(keyselect==5)jumpkey=keynum;
2375                                                         if(keyselect==6)drawkey=keynum;
2376                                                         if(keyselect==7)throwkey=keynum;
2377                                                         if(keyselect==8)attackkey=keynum;
2378                                                         keyselect=-1;
2379                                                 }
2380                                         }
2381                                 }}
2382                         if(Button()&&!oldbutton&&selected==9){
2383                                 float gLoc[3]={0,0,0};
2384                                 float vel[3]={0,0,0};
2385                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2386                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2387                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2388                                 FSOUND_SetVolume(channels[fireendsound], 256);
2389                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2390                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2391
2392                                 flashr=1;
2393                                 flashg=0;
2394                                 flashb=0;
2395                                 flashamount=1;
2396                                 flashdelay=1;
2397
2398                                 mainmenu=3;
2399
2400                                 if(newdetail>2)newdetail=detail;
2401                                 if(newdetail<0)newdetail=detail;
2402                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2403                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2404                                 if(newscreenheight>3000)newscreenheight=screenheight;
2405                                 if(newscreenheight<0)newscreenheight=screenheight;
2406                         }
2407                 }
2408
2409                 if(mainmenu==5){
2410                         if(accountcampaignchoicesmade[accountactive]>8&&!registered){
2411                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
2412                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
2413                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
2414                                 FSOUND_SetVolume(channels[stream_music3], 256);
2415
2416                                 gameon=0;
2417                                 mainmenu=12;
2418                                 accountcampaignchoicesmade[accountactive]=0;
2419                                 accountcampaignscore[accountactive]=0;
2420                                 accountcampaigntime[accountactive]=0;
2421
2422                                 float gLoc[3]={0,0,0};
2423                                 float vel[3]={0,0,0};
2424                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2425                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2426                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2427                                 FSOUND_SetVolume(channels[fireendsound], 256);
2428                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2429                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2430
2431                                 flashr=1;
2432                                 flashg=0;
2433                                 flashb=0;
2434                                 flashamount=1;
2435                                 flashdelay=1;
2436                         }
2437
2438                         if(endgame==2){
2439                                 accountcampaignchoicesmade[accountactive]=0;
2440                                 accountcampaignscore[accountactive]=0;
2441                                 accountcampaigntime[accountactive]=0;
2442                                 endgame=0;
2443                         }
2444
2445                         if(Button()&&!oldbutton&&selected==1){                  
2446                                 float gLoc[3]={0,0,0};
2447                                 float vel[3]={0,0,0};
2448                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2449                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2450                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2451                                 FSOUND_SetVolume(channels[firestartsound], 256);
2452                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2453                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2454
2455                                 flashr=1;
2456                                 flashg=0;
2457                                 flashb=0;
2458                                 flashamount=1;
2459                                 flashdelay=1;
2460
2461                                 startbonustotal=0;
2462
2463                                 loading=2;
2464                                 loadtime=0;
2465                                 targetlevel=-1;
2466                                 if(firstload)TickOnceAfter();
2467                                 if(!firstload)LoadStuff();
2468                                 else {
2469                                         Loadlevel(-1);
2470                                 }
2471
2472                                 mainmenu=0;
2473                                 gameon=1;
2474                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2475                         }
2476                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){                       
2477                                 float gLoc[3]={0,0,0};
2478                                 float vel[3]={0,0,0};
2479                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2480                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2481                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2482                                 FSOUND_SetVolume(channels[firestartsound], 256);
2483                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2484                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2485
2486                                 flashr=1;
2487                                 flashg=0;
2488                                 flashb=0;
2489                                 flashamount=1;
2490                                 flashdelay=1;
2491
2492                                 startbonustotal=0;
2493
2494                                 loading=2;
2495                                 loadtime=0;
2496                                 targetlevel=7;
2497                                 if(firstload)TickOnceAfter();
2498                                 if(!firstload)LoadStuff();
2499                                 //else {
2500                                 for(i=0;i<255;i++){
2501                                         mapname[i]='\0';
2502                                 }
2503                                 mapname[0]=':';
2504                                 mapname[1]='D';
2505                                 mapname[2]='a';
2506                                 mapname[3]='t';
2507                                 mapname[4]='a';
2508                                 mapname[5]=':';
2509                                 mapname[6]='M';
2510                                 mapname[7]='a';
2511                                 mapname[8]='p';
2512                                 mapname[9]='s';
2513                                 mapname[10]=':';
2514                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2515                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2516                                 visibleloading=1;
2517                                 stillloading=1;
2518                                 Loadlevel(mapname);
2519                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2520                                 //}
2521                                 campaign=1;
2522                                 mainmenu=0;
2523                                 gameon=1;
2524                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2525                         }
2526                         if(Button()&&!oldbutton&&selected==4){
2527                                 float gLoc[3]={0,0,0};
2528                                 float vel[3]={0,0,0};
2529                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2530                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2531                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2532                                 FSOUND_SetVolume(channels[fireendsound], 256);
2533                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2534                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2535
2536                                 flashr=1;
2537                                 flashg=0;
2538                                 flashb=0;
2539                                 flashamount=1;
2540                                 flashdelay=1;
2541
2542                                 if(mainmenu==5&&gameon)mainmenu=2;
2543                                 if(mainmenu==5&&!gameon)mainmenu=1;
2544                         }
2545                         if(Button()&&!oldbutton&&selected==5){
2546                                 float gLoc[3]={0,0,0};
2547                                 float vel[3]={0,0,0};
2548                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2549                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2550                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2551                                 FSOUND_SetVolume(channels[fireendsound], 256);
2552                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2553                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2554
2555                                 flashr=1;
2556                                 flashg=0;
2557                                 flashb=0;
2558                                 flashamount=1;
2559                                 flashdelay=1;
2560
2561                                 mainmenu=7;
2562                         }
2563                         if(Button()&&!oldbutton&&selected==3){
2564                                 float gLoc[3]={0,0,0};
2565                                 float vel[3]={0,0,0};
2566                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2567                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2568                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2569                                 FSOUND_SetVolume(channels[firestartsound], 256);
2570                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2571                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2572
2573                                 flashr=1;
2574                                 flashg=0;
2575                                 flashb=0;
2576                                 flashamount=1;
2577                                 flashdelay=1;
2578
2579                                 mainmenu=6;
2580                         }
2581                         if(Button()&&!oldbutton&&selected==2){
2582                                 float gLoc[3]={0,0,0};
2583                                 float vel[3]={0,0,0};
2584                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2585                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2586                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2587                                 FSOUND_SetVolume(channels[firestartsound], 256);
2588                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2589                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2590
2591                                 flashr=1;
2592                                 flashg=0;
2593                                 flashb=0;
2594                                 flashamount=1;
2595                                 flashdelay=1;
2596
2597                                 mainmenu=9;
2598                         }
2599                         if(Button())oldbutton=1;
2600                         else oldbutton=0;
2601                 }
2602                 if(mainmenu==9){
2603                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){                   
2604                                 float gLoc[3]={0,0,0};
2605                                 float vel[3]={0,0,0};
2606                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2607                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2608                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2609                                 FSOUND_SetVolume(channels[firestartsound], 256);
2610                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2611                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2612
2613                                 flashr=1;
2614                                 flashg=0;
2615                                 flashb=0;
2616                                 flashamount=1;
2617                                 flashdelay=1;
2618
2619                                 startbonustotal=0;
2620
2621                                 loading=2;
2622                                 loadtime=0;
2623                                 targetlevel=selected;
2624                                 if(firstload)TickOnceAfter();
2625                                 if(!firstload)LoadStuff();
2626                                 else {
2627                                         Loadlevel(selected);
2628                                 }
2629                                 campaign=0;
2630
2631                                 mainmenu=0;
2632                                 gameon=1;
2633                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2634                         }
2635                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2636                                 float gLoc[3]={0,0,0};
2637                                 float vel[3]={0,0,0};
2638                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2639                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2640                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2641                                 FSOUND_SetVolume(channels[fireendsound], 256);
2642                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2643                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2644
2645                                 flashr=1;
2646                                 flashg=0;
2647                                 flashb=0;
2648                                 flashamount=1;
2649                                 flashdelay=1;
2650
2651                                 mainmenu=5;
2652                         }
2653                         if(Button())oldbutton=1;
2654                         else oldbutton=0;
2655                 }
2656                 if(mainmenu==11){
2657                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){                   
2658                                 float gLoc[3]={0,0,0};
2659                                 float vel[3]={0,0,0};
2660                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2661                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2662                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2663                                 FSOUND_SetVolume(channels[firestartsound], 256);
2664                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2665                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2666
2667                                 flashr=1;
2668                                 flashg=0;
2669                                 flashb=0;
2670                                 flashamount=1;
2671                                 flashdelay=1;
2672
2673                                 startbonustotal=0;
2674
2675                                 loading=2;
2676                                 loadtime=0;
2677                                 targetlevel=selected;
2678                                 if(firstload)TickOnceAfter();
2679                                 if(!firstload)LoadStuff();
2680                                 else {
2681                                         Loadlevel(selected);
2682                                 }
2683                                 campaign=0;
2684
2685                                 mainmenu=0;
2686                                 gameon=1;
2687                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2688                         }
2689                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2690                                 float gLoc[3]={0,0,0};
2691                                 float vel[3]={0,0,0};
2692                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2693                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2694                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2695                                 FSOUND_SetVolume(channels[fireendsound], 256);
2696                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2697                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2698
2699                                 flashr=1;
2700                                 flashg=0;
2701                                 flashb=0;
2702                                 flashamount=1;
2703                                 flashdelay=1;
2704
2705                                 mainmenu=5;
2706                         }
2707                         if(Button())oldbutton=1;
2708                         else oldbutton=0;
2709                 }
2710                 if(mainmenu==10){
2711                         endgame=2;
2712                         if(Button()&&!oldbutton&&selected==3){
2713                                 float gLoc[3]={0,0,0};
2714                                 float vel[3]={0,0,0};
2715                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2716                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2717                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2718                                 FSOUND_SetVolume(channels[fireendsound], 256);
2719                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2720                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2721
2722                                 flashr=1;
2723                                 flashg=0;
2724                                 flashb=0;
2725                                 flashamount=1;
2726                                 flashdelay=1;
2727
2728                                 mainmenu=5;
2729                         }
2730                         if(Button())oldbutton=1;
2731                         else oldbutton=0;
2732                 }
2733
2734                 if(mainmenu==15||mainmenu==16){
2735                         if(Button()&&!oldbutton&&selected==1){
2736                                 float gLoc[3]={0,0,0};
2737                                 float vel[3]={0,0,0};
2738                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2739                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2740                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2741                                 FSOUND_SetVolume(channels[fireendsound], 256);
2742                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2743                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2744
2745                                 flashr=1;
2746                                 flashg=0;
2747                                 flashb=0;
2748                                 flashamount=1;
2749                                 flashdelay=1;
2750
2751                                 if(mainmenu==15)mainmenu=5;
2752                                 else mainmenu=12;
2753                         }
2754                         if(Button())oldbutton=1;
2755                         else oldbutton=0;
2756                 }
2757
2758                 if(mainmenu==12){
2759                         endgame=2;
2760                         if(Button()&&!oldbutton&&selected==3){
2761                                 if(tryquit)quit=1;
2762                                 float gLoc[3]={0,0,0};
2763                                 float vel[3]={0,0,0};
2764                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2765                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2766                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2767                                 FSOUND_SetVolume(channels[fireendsound], 256);
2768                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2769                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2770
2771                                 flashr=1;
2772                                 flashg=0;
2773                                 flashb=0;
2774                                 flashamount=1;
2775                                 flashdelay=1;
2776
2777                                 mainmenu=5;
2778                         }
2779
2780                         if(Button()&&!oldbutton&&selected==4){
2781                                 registernow=1;
2782                                 quit=1;
2783                                 float gLoc[3]={0,0,0};
2784                                 float vel[3]={0,0,0};
2785                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2786                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2787                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2788                                 FSOUND_SetVolume(channels[fireendsound], 256);
2789                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2790                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2791
2792                                 flashr=1;
2793                                 flashg=0;
2794                                 flashb=0;
2795                                 flashamount=1;
2796                                 flashdelay=1;
2797                         }
2798
2799
2800                         if(Button()&&!oldbutton&&selected==5){
2801                                 tryquit=0;
2802                                 float gLoc[3]={0,0,0};
2803                                 float vel[3]={0,0,0};
2804                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2805                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2806                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2807                                 FSOUND_SetVolume(channels[fireendsound], 256);
2808                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2809                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2810
2811                                 flashr=1;
2812                                 flashg=0;
2813                                 flashb=0;
2814                                 flashamount=1;
2815                                 flashdelay=1;
2816
2817                                 mainmenu=13;
2818                         }
2819                         if(Button())oldbutton=1;
2820                         else oldbutton=0;
2821                 }
2822                 if(mainmenu==6){
2823                         if(Button()&&!oldbutton&&selected!=-1){
2824                                 float gLoc[3]={0,0,0};
2825                                 float vel[3]={0,0,0};
2826                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2827                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2828                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2829                                 FSOUND_SetVolume(channels[firestartsound], 256);
2830                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2831                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2832                         }
2833                         if(Button()&&!oldbutton&&selected==1){
2834                                 float gLoc[3]={0,0,0};
2835                                 float vel[3]={0,0,0};
2836                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2837                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2838                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2839                                 FSOUND_SetVolume(channels[fireendsound], 256);
2840                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2841                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2842
2843                                 flashr=1;
2844                                 flashg=0;
2845                                 flashb=0;
2846                                 flashamount=1;
2847                                 flashdelay=1;
2848
2849                                 for(i=accountactive;i<numaccounts-1;i++){
2850                                         accountdifficulty[i]=accountdifficulty[i+1];
2851                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2852                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2853                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2854                                         }
2855                                         accountpoints[i]=accountpoints[i+1];
2856                                         for(j=0;j<50;j++){
2857                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2858                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2859                                         }
2860                                         for(j=0;j<60;j++){
2861                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2862                                         }
2863                                         for(j=0;j<256;j++){
2864                                                 accountname[i][j]=accountname[i+1][j];
2865                                         }
2866                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2867                                         accountprogress[i]=accountprogress[i+1];
2868                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2869                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2870                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2871                                 }
2872
2873                                 numaccounts--;
2874                                 accountactive=-1;
2875
2876
2877                                 mainmenu=7;
2878                         }
2879                         if(Button()&&!oldbutton&&selected==2){
2880                                 float gLoc[3]={0,0,0};
2881                                 float vel[3]={0,0,0};
2882                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2883                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2884                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2885                                 FSOUND_SetVolume(channels[fireendsound], 256);
2886                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2887                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2888
2889                                 flashr=1;
2890                                 flashg=0;
2891                                 flashb=0;
2892                                 flashamount=1;
2893                                 flashdelay=1;
2894
2895                                 mainmenu=5;
2896                         }
2897                         if(Button())oldbutton=1;
2898                         else oldbutton=0;
2899                 }
2900                 if(mainmenu==7){
2901                         if(Button()&&!oldbutton&&selected!=-1){
2902                                 float gLoc[3]={0,0,0};
2903                                 float vel[3]={0,0,0};
2904                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2905                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2906                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2907                                 FSOUND_SetVolume(channels[firestartsound], 256);
2908                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2909                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2910                         }
2911                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2912                                 entername=1;
2913                         }
2914                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2915                                 accountactive=selected-1;
2916                                 mainmenu=5;
2917                                 flashr=1;
2918                                 flashg=0;
2919                                 flashb=0;
2920                                 flashamount=1;
2921                                 flashdelay=1;
2922                         }
2923                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2924                                 float gLoc[3]={0,0,0};
2925                                 float vel[3]={0,0,0};
2926                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2927                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2928                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2929                                 FSOUND_SetVolume(channels[fireendsound], 256);
2930                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2931                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2932
2933                                 flashr=1;
2934                                 flashg=0;
2935                                 flashb=0;
2936                                 flashamount=1;
2937                                 flashdelay=1;
2938
2939                                 mainmenu=1;
2940
2941                                 for(j=0;j<255;j++){
2942                                         displaytext[0][j]=' ';
2943                                 }
2944                                 displaychars[0]=0;
2945                                 displayselected=0;
2946                                 entername=0;
2947                         }
2948                         if(Button())oldbutton=1;
2949                         else oldbutton=0;
2950                 }
2951                 if(mainmenu==8){
2952                         if(Button()&&!oldbutton&&selected!=-1){
2953                                 float gLoc[3]={0,0,0};
2954                                 float vel[3]={0,0,0};
2955                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2956                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2957                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2958                                 FSOUND_SetVolume(channels[firestartsound], 256);
2959                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2960                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2961
2962                                 if(selected==0)accountdifficulty[accountactive]=0;
2963                                 if(selected==1)accountdifficulty[accountactive]=1;
2964                                 if(selected==2)accountdifficulty[accountactive]=2;
2965
2966                                 mainmenu=5;     
2967
2968                                 flashr=1;
2969                                 flashg=0;
2970                                 flashb=0;
2971                                 flashamount=1;
2972                                 flashdelay=1;
2973
2974                         }
2975                         if(Button())oldbutton=1;
2976                         else oldbutton=0;
2977                 }
2978
2979
2980                 if(Button())oldbutton=1;
2981                 else oldbutton=0;
2982
2983                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
2984                         tryquit=1;
2985                         if(mainmenu==3){
2986                                 if(newdetail>2)newdetail=detail;
2987                                 if(newdetail<0)newdetail=detail;
2988                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2989                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2990                                 if(newscreenheight>3000)newscreenheight=screenheight;
2991                                 if(newscreenheight<0)newscreenheight=screenheight;
2992
2993                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2994                                 opstream << "Screenwidth:\n";
2995                                 opstream << newscreenwidth;
2996                                 opstream << "\nScreenheight:\n";
2997                                 opstream << newscreenheight;
2998                                 opstream << "\nMouse sensitivity:\n";
2999                                 opstream << usermousesensitivity;
3000                                 opstream << "\nBlur(0,1):\n";
3001                                 opstream << ismotionblur;
3002                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
3003                                 opstream << newdetail;
3004                                 opstream << "\nFloating jump:\n";
3005                                 opstream << floatjump;
3006                                 opstream << "\nMouse jump:\n";
3007                                 opstream << mousejump;
3008                                 opstream << "\nAmbient sound:\n";
3009                                 opstream << ambientsound;
3010                                 opstream << "\nBlood (0,1,2):\n";
3011                                 opstream << bloodtoggle;
3012                                 opstream << "\nAuto slomo:\n";
3013                                 opstream << autoslomo;
3014                                 opstream << "\nFoliage:\n";
3015                                 opstream << foliage;
3016                                 opstream << "\nMusic:\n";
3017                                 opstream << musictoggle;
3018                                 opstream << "\nTrilinear:\n";
3019                                 opstream << trilinear;
3020                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
3021                                 opstream << decals;
3022                                 opstream << "\nInvert mouse:\n";
3023                                 opstream << invertmouse;
3024                                 opstream << "\nGamespeed:\n";
3025                                 if(oldgamespeed==0)oldgamespeed=1;
3026                                 opstream << oldgamespeed;
3027                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
3028                                 opstream << difficulty;
3029                                 opstream << "\nDamage effects(blackout, doublevision):\n";
3030                                 opstream << damageeffects;
3031                                 opstream << "\nText:\n";
3032                                 opstream << texttoggle;
3033                                 opstream << "\nDebug:\n";
3034                                 opstream << debugmode;
3035                                 opstream << "\nVBL Sync:\n";
3036                                 opstream << vblsync;
3037                                 opstream << "\nShow Points:\n";
3038                                 opstream << showpoints;
3039                                 opstream << "\nAlways Blur:\n";
3040                                 opstream << alwaysblur;
3041                                 opstream << "\nImmediate mode (turn on on G5):\n";
3042                                 opstream << immediate;
3043                                 opstream << "\nVelocity blur:\n";
3044                                 opstream << velocityblur;
3045                             opstream << "\nVolume:\n";
3046                         opstream << volume;
3047                                 opstream << "\nForward key:\n";
3048                                 opstream << KeyToChar(forwardkey);
3049                                 opstream << "\nBack key:\n";
3050                                 opstream << KeyToChar(backkey);
3051                                 opstream << "\nLeft key:\n";
3052                                 opstream << KeyToChar(leftkey);
3053                                 opstream << "\nRight key:\n";
3054                                 opstream << KeyToChar(rightkey);
3055                                 opstream << "\nJump key:\n";
3056                                 opstream << KeyToChar(jumpkey);
3057                                 opstream << "\nCrouch key:\n";
3058                                 opstream << KeyToChar(crouchkey);
3059                                 opstream << "\nDraw key:\n";
3060                                 opstream << KeyToChar(drawkey);
3061                                 opstream << "\nThrow key:\n";
3062                                 opstream << KeyToChar(throwkey);
3063                                 opstream << "\nAttack key:\n";
3064                                 opstream << KeyToChar(attackkey);
3065                                 opstream << "\nChat key:\n";
3066                                 opstream << KeyToChar(chatkey);
3067                                 opstream.close();
3068                         }
3069                 }
3070
3071                 if(mainmenu==1||mainmenu==2){
3072                         if(loaddistrib>4)transition+=multiplier/8;
3073                         if(transition>1){
3074                                 transition=0;
3075                                 anim++;
3076                                 if(anim>4)anim=0;
3077                                 loaddistrib=0;
3078                         }
3079                 }
3080                 FSOUND_SetFrequency(channels[stream_music3], 22050);            
3081
3082                 if(entername||mainmenu==13||mainmenu==14){
3083                         for(i=0;i<140;i++){
3084                                 if(IsKeyDown(theKeyMap, i)){
3085                                         togglekeydelay[i]+=multiplier;
3086                                         if(togglekeydelay[i]>.4){
3087                                                 togglekey[i]=0;
3088                                                 togglekeydelay[i]=.36;
3089                                         }
3090                                         if(!togglekey[i]){
3091                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3092                                                         for(j=255;j>=displayselected+1;j--){
3093                                                                 displaytext[0][j]=displaytext[0][j-1];
3094                                                         }
3095                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3096                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3097                                                         displayselected++;
3098                                                         displaychars[0]++;
3099                                                 }
3100                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3101                                                         for(j=displayselected-1;j<255;j++){
3102                                                                 displaytext[0][j]=displaytext[0][j+1];
3103                                                         }
3104                                                         displaytext[0][255]=' ';
3105                                                         displayselected--;
3106                                                         displaychars[0]--;
3107                                                 }
3108                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3109                                                         displayselected--;
3110                                                 }
3111                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3112                                                         displayselected++;
3113                                                 }
3114                                                 if(i==MAC_RETURN_KEY&&entername){
3115                                                         if(displaychars[0]){
3116                                                                 numaccounts++;
3117                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
3118                                                                 accountactive=numaccounts-1;
3119                                                                 accountdifficulty[accountactive]=1;
3120                                                                 accountprogress[accountactive]=0;
3121                                                                 accountpoints[accountactive]=0;
3122                                                                 accountcampaigntime[accountactive]=0;
3123                                                                 accountcampaignscore[accountactive]=0;
3124                                                                 accountcampaignfasttime[accountactive]=0;
3125                                                                 accountcampaignhighscore[accountactive]=0;
3126                                                                 for(j=0;j<50;j++){
3127                                                                         accounthighscore[accountactive][j]=0;
3128                                                                         accountfasttime[accountactive][j]=0;
3129                                                                 }
3130                                                                 for(j=0;j<60;j++){
3131                                                                         accountunlocked[accountactive][j]=0;
3132                                                                 }
3133                                                                 accountcampaignchoicesmade[accountactive]=0;
3134
3135                                                                 for(j=0;j<255;j++){
3136                                                                         displaytext[0][j]=' ';
3137                                                                 }
3138                                                                 displaychars[0]=0;
3139                                                                 displayselected=0;
3140                                                                 entername=0;
3141
3142                                                                 mainmenu=8;
3143
3144                                                                 flashr=1;
3145                                                                 flashg=0;
3146                                                                 flashb=0;
3147                                                                 flashamount=1;
3148                                                                 flashdelay=1;
3149
3150                                                                 float gLoc[3]={0,0,0};
3151                                                                 float vel[3]={0,0,0};
3152                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3153                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3154                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3155                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3156                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3157                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3158
3159                                                                 for(j=0;j<255;j++){
3160                                                                         displaytext[0][j]=' ';
3161                                                                 }
3162                                                                 displaychars[0]=0;
3163
3164
3165                                                                 displayselected=0;
3166                                                         }}
3167
3168                                                 if(i==MAC_RETURN_KEY&&mainmenu==14){
3169                                                         if(displaychars[0]){
3170                                                                 char serialstring[256];
3171                                                                 char tempstring[256];
3172                                                                 sprintf (tempstring, "%s-windows", registrationname);
3173                                                                 long num1;
3174                                                                 long num2;
3175                                                                 long num3;
3176                                                                 long num4;
3177                                                                 long long longnum;
3178                                                                 longnum = MD5_string ( tempstring);
3179                                                                 //longnum = 1111111111111111;
3180                                                                 num1 = longnum/100000000;
3181                                                                 num2 = longnum%100000000;
3182                                                                 sprintf (tempstring, "%d-%d-%d-%d\0\0\0\0\0", num1/10000, num1%10000, num2/10000, num2%10000);
3183
3184                                                                 int goodcode=3;
3185                                                                 int numchars=3;
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(num1%10000>999)numchars+=4;
3191                                                                 else if(num1%10000>99)numchars+=3;
3192                                                                 else if(num1%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                                                                 if(num2%10000>999)numchars+=4;
3199                                                                 else if(num2%10000>99)numchars+=3;
3200                                                                 else if(num2%10000>9)numchars+=2;
3201                                                                 else numchars+=1;
3202
3203                                                                 //numchars=12;
3204
3205                                                                 for(j=0;j<numchars;j++){
3206                                                                         if(displaytext[0][j]!=tempstring[j]&&tempstring[j]!=' '&&tempstring[j]!='\0')goodcode--;
3207                                                                 }
3208
3209                                                                 if(longnum==LONGLONGCONST(5077041556214789))goodcode=-1;
3210
3211                                                                 if(goodcode<0)goodcode=0;
3212
3213                                                                 if(goodcode){
3214                                                                         registered=1;
3215                                                                         mainmenu=15;
3216
3217                                                                         FILE                    *tfile;
3218                                                                         tfile=fopen( ":Data:Sounds:flame.ogg", "wb" );
3219                                                                         if (tfile)
3220                                                                         {
3221                                                                                 int numchars;
3222                                                                                 numchars=strlen(registrationname);
3223                                                                                 fpackf(tfile, "Bb", registered);
3224                                                                                 fpackf(tfile, "Bi", numchars);
3225                                                                                 if(numchars>0)
3226                                                                                 {
3227                                                                                         for(j=0;j<numchars;j++)
3228                                                                                         {
3229                                                                                                 fpackf(tfile, "Bb",  registrationname[j]);
3230                                                                                         }
3231                                                                                 }
3232                                                                                 fpackf(tfile, "Bi", num1);
3233                                                                                 fpackf(tfile, "Bi", num2);
3234                                                                                 fclose(tfile);
3235                                                                         }
3236                                                                 }
3237                                                                 else
3238                                                                 {
3239                                                                         mainmenu=16;
3240                                                                 }
3241                                                                 flashr=1;
3242                                                                 flashg=0;
3243                                                                 flashb=0;
3244                                                                 flashamount=1;
3245                                                                 flashdelay=1;
3246
3247                                                                 float gLoc[3]={0,0,0};
3248                                                                 float vel[3]={0,0,0};
3249                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3250                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3251                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3252                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3253                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3254                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3255
3256                                                                 for(j=0;j<255;j++){
3257                                                                         displaytext[0][j]=' ';
3258                                                                 }
3259                                                                 displaychars[0]=0;
3260                                                                 displayselected=0;
3261                                                         }}
3262
3263                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3264                                                         if(displaychars[0]){
3265                                                                 sprintf (registrationname, "%s", displaytext[0]);
3266                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3267
3268                                                                 mainmenu=14;
3269
3270                                                                 flashr=1;
3271                                                                 flashg=0;
3272                                                                 flashb=0;
3273                                                                 flashamount=1;
3274                                                                 flashdelay=1;
3275
3276                                                                 float gLoc[3]={0,0,0};
3277                                                                 float vel[3]={0,0,0};
3278                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3279                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3280                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3281                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3282                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3283                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3284
3285                                                                 for(j=0;j<255;j++){
3286                                                                         displaytext[0][j]=' ';
3287                                                                 }
3288                                                                 displaychars[0]=0;
3289
3290                                                                 /*char tempstring[50];
3291                                                                 sprintf (tempstring, registrationname);
3292                                                                 long num1;
3293                                                                 long num2;
3294                                                                 long num3;
3295                                                                 long num4;
3296                                                                 long long longnum;
3297                                                                 longnum = MD5_string ( tempstring);
3298                                                                 num1 = longnum/100000000;
3299                                                                 num2 = longnum%100000000;
3300                                                                 sprintf (displaytext[0], "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
3301
3302                                                                 displaychars[0]=strlen(displaytext[0]);
3303                                                                 */
3304                                                                 displayselected=0;
3305                                                         }}
3306                                         }
3307                                         togglekey[i]=1;
3308                                 }
3309                                 else {
3310                                         togglekey[i]=0;
3311                                         togglekeydelay[i]=0;
3312                                 }
3313                         }
3314
3315                         displayblinkdelay-=multiplier;
3316                         if(displayblinkdelay<=0){
3317                                 displayblinkdelay=.3;
3318                                 displayblink=1-displayblink;
3319                         }
3320                 }
3321         }
3322
3323         if(!mainmenu){  
3324                 if(hostile==1)hostiletime+=multiplier;
3325                 else hostiletime=0;
3326                 if(!winfreeze)leveltime+=multiplier;
3327                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3328                         chatting=0;
3329                         console=0;
3330                         freeze=0;
3331                         displaychars[0]=0;
3332                 }
3333
3334                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3335                         chatting=1;
3336                         chattogglekeydown=1;
3337                         togglekey[chatkey]=1;
3338                         togglekeydelay[chatkey]=-20;
3339                 }
3340
3341                 if(!IsKeyDown(theKeyMap, chatkey)){
3342                         chattogglekeydown=0;
3343                 }
3344
3345                 if(chatting){
3346                         for(i=0;i<140;i++){
3347                                 if(IsKeyDown(theKeyMap, i)){
3348                                         togglekeydelay[i]+=multiplier;
3349                                         if(togglekeydelay[i]>.4){
3350                                                 togglekey[i]=0;
3351                                                 togglekeydelay[i]=.36;
3352                                         }
3353                                         if(!togglekey[i]){
3354                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3355                                                         for(j=255;j>=displayselected+1;j--){
3356                                                                 displaytext[0][j]=displaytext[0][j-1];
3357                                                         }
3358                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3359                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3360                                                         displayselected++;
3361                                                         displaychars[0]++;
3362                                                 }
3363                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3364                                                         for(j=displayselected-1;j<255;j++){
3365                                                                 displaytext[0][j]=displaytext[0][j+1];
3366                                                         }
3367                                                         displaytext[0][255]=' ';
3368                                                         displayselected--;
3369                                                         displaychars[0]--;
3370                                                 }
3371                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3372                                                         displayselected--;
3373                                                 }
3374                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3375                                                         displayselected++;
3376                                                 }
3377                                                 if(i==MAC_RETURN_KEY){
3378                                                         if(displaychars[0]){
3379                                                                 /*for(j=0;j<displaychars[0];j++){
3380                                                                 talkname[j]=displaytext[0][j];
3381                                                                 }
3382                                                                 talkname[displaychars[0]]='\0';
3383                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3384                                                                 //NetworkSendInformation(chatname);
3385                                                                 */
3386                                                                 for(j=0;j<255;j++){
3387                                                                         displaytext[0][j]=' ';
3388                                                                 }
3389                                                                 displaychars[0]=0;
3390                                                                 displayselected=0;
3391                                                                 chatting=0;
3392                                                         }
3393                                                 }
3394                                         }
3395                                         togglekey[i]=1;
3396                                 }
3397                                 else {
3398                                         togglekey[i]=0;
3399                                         togglekeydelay[i]=0;
3400                                 }
3401                         }
3402
3403                         displayblinkdelay-=multiplier;
3404                         if(displayblinkdelay<=0){
3405                                 displayblinkdelay=.3;
3406                                 displayblink=1-displayblink;
3407                         }
3408                 }
3409
3410                 if(chatting)keyboardfrozen=1;
3411
3412                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3413                         freeze=1-freeze;
3414                         if(freeze){
3415                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3416                         }
3417                         freezetogglekeydown=1;
3418                 }
3419
3420                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3421                         freezetogglekeydown=0;
3422                 }
3423
3424                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3425                         console=1-console;
3426                         if(!console)freeze=0;
3427                         if(console){
3428                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3429                         }
3430                         consoletogglekeydown=1;
3431                 }
3432
3433                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3434                         consoletogglekeydown=0;
3435                 }
3436
3437                 if(console)freeze=1;
3438
3439                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3440                         for(i=0;i<140;i++){
3441                                 if(IsKeyDown(theKeyMap, i)){
3442                                         togglekeydelay[i]+=multiplier;
3443                                         if(togglekeydelay[i]>.4){
3444                                                 togglekey[i]=0;
3445                                                 togglekeydelay[i]=.36;
3446                                         }
3447                                         if(!togglekey[i]){
3448                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3449                                                         for(j=255;j>=consoleselected+1;j--){
3450                                                                 consoletext[0][j]=consoletext[0][j-1];
3451                                                         }
3452                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3453                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3454                                                         consoleselected++;
3455                                                         consolechars[0]++;
3456                                                 }
3457                                                 else if(i==MAC_ENTER_KEY){
3458                                                         for(j=255;j>=consoleselected+1;j--){
3459                                                                 consoletext[0][j]=consoletext[0][j-1];
3460                                                         }
3461                                                         consoletext[0][consoleselected]='\n';
3462                                                         consoleselected++;
3463                                                         consolechars[0]++;
3464                                                 }
3465                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3466                                                         for(j=consoleselected-1;j<255;j++){
3467                                                                 consoletext[0][j]=consoletext[0][j+1];
3468                                                         }
3469                                                         consoletext[0][255]=' ';
3470                                                         consoleselected--;
3471                                                         consolechars[0]--;
3472                                                 }
3473                                                 if(i==MAC_ARROW_UP_KEY){
3474                                                         if(archiveselected<14)archiveselected++;
3475                                                         for(j=0;j<255;j++){
3476                                                                 consolechars[0]=consolechars[archiveselected];
3477                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3478                                                                 consoleselected=consolechars[0];
3479                                                         }
3480                                                 }
3481                                                 if(i==MAC_ARROW_DOWN_KEY){
3482                                                         if(archiveselected>0)archiveselected--;
3483                                                         for(j=0;j<255;j++){
3484                                                                 consolechars[0]=consolechars[archiveselected];
3485                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3486                                                                 consoleselected=consolechars[0];
3487                                                         }
3488                                                 }
3489                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3490                                                         consoleselected--;
3491                                                 }
3492                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3493                                                         consoleselected++;
3494                                                 }
3495                                                 if(i==MAC_RETURN_KEY){
3496                                                         archiveselected=0;
3497                                                         donesomething=0;
3498                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3499                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3500                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3501                                                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3502                                                                 donesomething=1;
3503                                                                 tryquit=1;
3504                                                         }
3505                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3506                                                         for(j=5;j<consolechars[0];j++){
3507                                                         talkname[j-5]=consoletext[0][j];
3508                                                         }
3509                                                         talkname[consolechars[0]-5]='\0';
3510                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3511                                                         //NetworkSendInformation(chatname);
3512                                                         donesomething=1;
3513                                                         }
3514                                                         if(Compare(consoletext[0],"name ",0,4)){
3515                                                         int numchars;
3516                                                         numchars=consolechars[0]-5;
3517                                                         if(numchars>32)numchars=32;
3518                                                         for(j=5;j<numchars+5;j++){
3519                                                         talkname[j-5]=consoletext[0][j];
3520                                                         }
3521                                                         talkname[numchars]='\0';
3522                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3523                                                         //NetworkSendInformation(chatname);
3524                                                         sprintf (playerName, "%s",talkname);
3525                                                         //NetworkSendName(playerName);
3526                                                         donesomething=1;
3527                                                         }*/
3528                                                         if(Compare(consoletext[0],"map ",0,3)){
3529                                                                 mapname[0]=':';
3530                                                                 mapname[1]='D';
3531                                                                 mapname[2]='a';
3532                                                                 mapname[3]='t';
3533                                                                 mapname[4]='a';
3534                                                                 mapname[5]=':';
3535                                                                 mapname[6]='M';
3536                                                                 mapname[7]='a';
3537                                                                 mapname[8]='p';
3538                                                                 mapname[9]='s';
3539                                                                 mapname[10]=':';
3540                                                                 for(j=4;j<consolechars[0];j++){
3541                                                                         mapname[j-4+11]=consoletext[0][j];
3542                                                                 }
3543                                                                 mapname[consolechars[0]-4+11]='\0';
3544                                                                 Loadlevel(mapname);
3545                                                                 whichlevel=-2;
3546                                                                 campaign=0;
3547                                                                 donesomething=1;
3548                                                         }
3549                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3550                                                         int v;
3551                                                         unsigned char playerNameStr[32];
3552                                                         char theIPAddress[256];
3553                                                         char thePort[32];
3554                                                         NMUInt32 port = 25710;
3555
3556                                                         strcpy(playerName, "Client");
3557                                                         GameC2PStr( playerName, playerNameStr );
3558
3559                                                         for(j=0;j<consolechars[0]-8;j++){
3560                                                         theIPAddress[j]=consoletext[0][j+8];
3561                                                         }
3562                                                         theIPAddress[consolechars[0]-8]='\0';
3563
3564                                                         sprintf( thePort, "%li", port );
3565                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3566                                                         if(v)
3567                                                         {
3568                                                         if(consolechars[0]>0){
3569                                                         for(k=14;k>=1;k--){
3570                                                         for(j=0;j<255;j++){
3571                                                         consoletext[k][j]=consoletext[k-1][j];
3572                                                         }
3573                                                         consolechars[k]=consolechars[k-1];
3574                                                         }
3575                                                         for(j=0;j<255;j++){
3576                                                         consoletext[0][j]=' ';
3577                                                         }
3578                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3579                                                         else sprintf (consoletext[0], "Could not open connection");
3580
3581                                                         consolechars[0]=255;
3582                                                         consoleselected=0;
3583                                                         }
3584                                                         }
3585                                                         else 
3586                                                         {
3587                                                         donesomething=1;
3588                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3589                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3590                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3591
3592                                                         if(consolechars[0]>0){
3593                                                         for(k=14;k>=1;k--){
3594                                                         for(j=0;j<255;j++){
3595                                                         consoletext[k][j]=consoletext[k-1][j];
3596                                                         }
3597                                                         consolechars[k]=consolechars[k-1];
3598                                                         }
3599                                                         for(j=0;j<255;j++){
3600                                                         consoletext[0][j]=' ';
3601                                                         }
3602                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3603
3604                                                         consolechars[0]=255;
3605                                                         consoleselected=0;
3606                                                         }
3607                                                         }
3608                                                         }
3609
3610                                                         if(Compare(consoletext[0],"host ",0,4)){
3611                                                         unsigned char gameNameStr[32], playerNameStr[32];
3612                                                         char gameName[32];//, playerName[32];
3613                                                         NMUInt32 port;
3614                                                         int players;
3615                                                         int v;
3616
3617                                                         port = 25710;
3618                                                         players =4;
3619
3620                                                         strcpy(gameName, "Host's game");
3621                                                         strcpy(playerName, "Host");
3622                                                         GameC2PStr( gameName, gameNameStr );
3623                                                         GameC2PStr( playerName, playerNameStr );
3624
3625                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3626                                                         if(v)
3627                                                         {
3628                                                         if(consolechars[0]>0){
3629                                                         for(k=14;k>=1;k--){
3630                                                         for(j=0;j<255;j++){
3631                                                         consoletext[k][j]=consoletext[k-1][j];
3632                                                         }
3633                                                         consolechars[k]=consolechars[k-1];
3634                                                         }
3635                                                         for(j=0;j<255;j++){
3636                                                         consoletext[0][j]=' ';
3637                                                         }
3638                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3639
3640                                                         consolechars[0]=255;
3641                                                         consoleselected=0;
3642                                                         }
3643                                                         }
3644                                                         else
3645                                                         {
3646                                                         donesomething=1;
3647                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3648                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3649                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3650
3651                                                         if(consolechars[0]>0){
3652                                                         for(k=14;k>=1;k--){
3653                                                         for(j=0;j<255;j++){
3654                                                         consoletext[k][j]=consoletext[k-1][j];
3655                                                         }
3656                                                         consolechars[k]=consolechars[k-1];
3657                                                         }
3658                                                         for(j=0;j<255;j++){
3659                                                         consoletext[0][j]=' ';
3660                                                         }
3661                                                         sprintf (consoletext[0], "Game hosted");
3662
3663                                                         consolechars[0]=255;
3664                                                         consoleselected=0;
3665                                                         }
3666                                                         }
3667                                                         }
3668                                                         */
3669                                                         if(Compare(consoletext[0],"save ",0,4)){
3670                                                                 mapname[0]=':';
3671                                                                 mapname[1]='D';
3672                                                                 mapname[2]='a';
3673                                                                 mapname[3]='t';
3674                                                                 mapname[4]='a';
3675                                                                 mapname[5]=':';
3676                                                                 mapname[6]='M';
3677                                                                 mapname[7]='a';
3678                                                                 mapname[8]='p';
3679                                                                 mapname[9]='s';
3680                                                                 mapname[10]=':';
3681                                                                 for(j=5;j<consolechars[0];j++){
3682                                                                         mapname[j-5+11]=consoletext[0][j];
3683                                                                 }
3684                                                                 mapname[consolechars[0]-5+11]='\0';
3685
3686                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3687                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3688                                                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3689
3690                                                                 int mapvers;
3691                                                                 mapvers=12;
3692
3693
3694                                                                 FILE                    *tfile;
3695                                                                 tfile=fopen( mapname, "wb" );
3696                                                                 fpackf(tfile, "Bi", mapvers);
3697                                                                 //fpackf(tfile, "Bi", indemo);
3698                                                                 fpackf(tfile, "Bi", maptype);
3699                                                                 fpackf(tfile, "Bi", hostile);
3700                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3701                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3702                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3703                                                                 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);
3704                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3705                                                                         for(j=0;j<player[0].num_weapons;j++){
3706                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3707                                                                         }
3708
3709                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3710                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3711                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3712                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3713
3714                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3715
3716                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3717
3718                                                                         fpackf(tfile, "Bi", numdialogues);
3719                                                                         if(numdialogues)
3720                                                                                 for(k=0;k<numdialogues;k++){
3721                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3722                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3723                                                                                         for(l=0;l<10;l++){
3724                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3725                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3726                                                                                         }
3727                                                                                         if(numdialogueboxes)
3728                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3729                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3730                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3731                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3732                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3733                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3734
3735                                                                                                         templength=strlen(dialoguetext[k][l]);
3736                                                                                                         fpackf(tfile, "Bi",(templength));
3737                                                                                                         for(m=0;m<templength;m++){
3738                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3739                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3740                                                                                                         }
3741
3742                                                                                                         templength=strlen(dialoguename[k][l]);
3743                                                                                                         fpackf(tfile, "Bi",templength);
3744                                                                                                         for(m=0;m<templength;m++){
3745                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3746                                                                                                                 if(dialoguename[k][l][m]=='\0')break;   
3747                                                                                                         }
3748
3749                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3750                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3751                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3752
3753                                                                                                         for(m=0;m<10;m++)
3754                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3755
3756                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3757                                                                                                 }
3758                                                                                 }
3759
3760                                                                                 if(player[0].numclothes)
3761                                                                                         for(k=0;k<player[0].numclothes;k++){
3762                                                                                                 templength=strlen(player[0].clothes[k]);
3763                                                                                                 fpackf(tfile, "Bi", templength);
3764                                                                                                 for(l=0;l<templength;l++)
3765                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3766                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);                                                                                                                                             
3767                                                                                         }
3768
3769                                                                                         fpackf(tfile, "Bi", environment);
3770
3771                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3772
3773                                                                                         if(objects.numobjects)
3774                                                                                                 for(k=0;k<objects.numobjects;k++){
3775                                                                                                         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]);
3776                                                                                                 }
3777
3778                                                                                                 fpackf(tfile, "Bi", numhotspots);
3779                                                                                                 if(numhotspots)
3780                                                                                                         for(i=0;i<numhotspots;i++){
3781                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3782                                                                                                                 templength=strlen(hotspottext[i]);
3783                                                                                                                 fpackf(tfile, "Bi",templength);
3784                                                                                                                 for(l=0;l<templength;l++)
3785                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3786                                                                                                         }
3787
3788                                                                                                         fpackf(tfile, "Bi", numplayers);
3789                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3790                                                                                                                 for(j=1;j<numplayers;j++){
3791                                                                                                                         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);
3792                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3793                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3794                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3795                                                                                                                                 }
3796                                                                                                                                 if(player[j].numwaypoints<30){
3797                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3798                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3799                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3800                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3801                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3802                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3803                                                                                                                                         }
3804                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3805                                                                                                                                 }
3806                                                                                                                                 else{
3807                                                                                                                                         player[j].numwaypoints=0;
3808                                                                                                                                         player[j].waypoint=0;
3809                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3810                                                                                                                                 }
3811
3812                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3813                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3814                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3815                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3816
3817                                                                                                                                 if(player[j].creature==wolftype){
3818                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3819                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3820                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3821                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3822                                                                                                                                 }
3823
3824                                                                                                                                 if(player[j].creature==rabbittype){
3825                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3826                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3827                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3828                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3829                                                                                                                                 }
3830
3831                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3832
3833
3834
3835                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3836                                                                                                                                 if(player[j].numclothes)
3837                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3838                                                                                                                                                 int templength;
3839                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3840                                                                                                                                                 fpackf(tfile, "Bi", templength);
3841                                                                                                                                                 for(l=0;l<templength;l++)
3842                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3843                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);                                                                                                                             
3844                                                                                                                                         }
3845                                                                                                                 }
3846
3847                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3848                                                                                                                 if(numpathpoints)
3849                                                                                                                         for(j=0;j<numpathpoints;j++){
3850                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3851                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3852                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3853                                                                                                                                 }
3854                                                                                                                         }
3855
3856                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3857
3858
3859                                                                                                                         fclose(tfile);
3860                                                                                                                         donesomething=1;
3861
3862                                                                                                                         /*
3863                                                                                                                         FILE                    *tfile;
3864                                                                                                                         tfile=fopen( mapname, "wb" );
3865                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3866                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3867                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3868                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3869                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3870                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3871                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3872                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3873                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3874                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3875                                                                                                                         }
3876
3877                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3878                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3879                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3880                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3881                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3882                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3883                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3884                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3885                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3886                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3887                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3888
3889                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3890                                                                                                                         if(player[0].numclothes)
3891                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3892                                                                                                                         int templength;
3893                                                                                                                         templength=strlen(player[0].clothes[k]);
3894                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);       
3895                                                                                                                         for(l=0;l<templength;l++)
3896                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3897                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);      
3898                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);      
3899                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);                                                                              
3900                                                                                                                         }
3901
3902                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3903
3904                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3905
3906                                                                                                                         for(k=0;k<objects.numobjects;k++){
3907                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3908                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3909                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3910                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3911                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3912                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3913                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3914                                                                                                                         }
3915
3916                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3917                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3918                                                                                                                         for(j=1;j<numplayers;j++){
3919                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3920                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3921                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3922                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3923                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3924                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3925                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3926                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3927                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3928                                                                                                                         }
3929                                                                                                                         if(player[j].numwaypoints<30){
3930                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3931                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3932                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3933                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3934                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3935                                                                                                                         }
3936                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3937                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3938                                                                                                                         }
3939                                                                                                                         else{
3940                                                                                                                         player[j].numwaypoints=0;
3941                                                                                                                         player[j].waypoint=0;
3942                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3943                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3944                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3945                                                                                                                         }
3946                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
3947                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
3948                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
3949                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
3950                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
3951                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
3952                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
3953                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
3954                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
3955                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
3956                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
3957
3958                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
3959                                                                                                                         if(player[j].numclothes)
3960                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3961                                                                                                                         int templength;
3962                                                                                                                         templength=strlen(player[j].clothes[k]);
3963                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);       
3964                                                                                                                         for(l=0;l<templength;l++)
3965                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
3966                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);      
3967                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);      
3968                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);                                                                              
3969                                                                                                                         }
3970                                                                                                                         }
3971                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3972                                                                                                                         if(numpathpoints)
3973                                                                                                                         for(j=0;j<numpathpoints;j++){
3974                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
3975                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
3976                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
3977                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3978                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
3979                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3980                                                                                                                         }
3981                                                                                                                         }
3982
3983                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
3984                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
3985                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
3986
3987                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
3988
3989                                                                                                                         fclose(tfile);
3990                                                                                                                         donesomething=1;*/
3991                                                         }
3992                                                         /*
3993                                                         if(Compare(consoletext[0],"save ",0,4)){
3994                                                         mapname[0]=':';
3995                                                         mapname[1]='D';
3996                                                         mapname[2]='a';
3997                                                         mapname[3]='t';
3998                                                         mapname[4]='a';
3999                                                         mapname[5]=':';
4000                                                         mapname[6]='M';
4001                                                         mapname[7]='a';
4002                                                         mapname[8]='p';
4003                                                         mapname[9]='s';
4004                                                         mapname[10]=':';
4005                                                         for(j=5;j<consolechars[0];j++){
4006                                                         mapname[j-5+11]=consoletext[0][j];
4007                                                         }
4008                                                         mapname[consolechars[0]-5+11]='\0';
4009
4010                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
4011                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
4012                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
4013
4014                                                         FILE                    *tfile;
4015                                                         tfile=fopen( mapname, "wb" );
4016                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
4017                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
4018                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
4019                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
4020                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
4021                                                         for(j=0;j<player[0].num_weapons;j++){
4022                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
4023                                                         }
4024                                                         fwrite( &environment, 1, sizeof(int), tfile );
4025
4026                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
4027                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
4028                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
4029                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
4030                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
4031
4032                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4033                                                         if(numplayers>1&&numplayers<maxplayers)
4034                                                         for(j=1;j<numplayers;j++){
4035                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
4036                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4037                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4038                                                         for(k=0;k<player[j].num_weapons;k++){
4039                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4040                                                         }
4041                                                         if(player[j].numwaypoints<30){
4042                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4043                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
4044                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4045                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4046                                                         }
4047                                                         else{
4048                                                         player[j].numwaypoints=0;
4049                                                         player[j].waypoint=0;
4050                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4051                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4052                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4053                                                         }
4054                                                         }
4055                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4056                                                         if(numpathpoints)
4057                                                         for(j=0;j<numpathpoints;j++){
4058                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
4059                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4060                                                         for(k=0;k<numpathpointconnect[j];k++){
4061                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4062                                                         }
4063                                                         }
4064                                                         fclose(tfile);
4065                                                         donesomething=1;
4066                                                         }*/
4067                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
4068                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4069                                                                 donesomething=1;
4070                                                         }
4071                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
4072                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
4073                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
4074                                                         donesomething=1;
4075                                                         }*/
4076
4077                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
4078                                                                 for(j=6;j<consolechars[0];j++){
4079                                                                         mapname[j-6]=consoletext[0][j];
4080                                                                 }
4081
4082                                                                 tintr=atof(mapname);
4083
4084                                                                 donesomething=1;
4085                                                         }
4086
4087                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
4088                                                                 for(j=6;j<consolechars[0];j++){
4089                                                                         mapname[j-6]=consoletext[0][j];
4090                                                                 }
4091
4092                                                                 player[0].speedmult=atof(mapname);
4093
4094                                                                 donesomething=1;
4095                                                         }
4096
4097                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
4098                                                                 for(j=9;j<consolechars[0];j++){
4099                                                                         mapname[j-9]=consoletext[0][j];
4100                                                                 }
4101
4102                                                                 player[0].power=atof(mapname);
4103
4104                                                                 donesomething=1;
4105                                                         }
4106
4107                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
4108                                                                 for(j=13;j<consolechars[0];j++){
4109                                                                         mapname[j-13]=consoletext[0][j];
4110                                                                 }
4111
4112                                                                 viewdistance=atof(mapname)*100;
4113
4114                                                                 donesomething=1;
4115                                                         }
4116
4117                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
4118                                                                 for(j=10;j<consolechars[0];j++){
4119                                                                         mapname[j-10]=consoletext[0][j];
4120                                                                 }
4121
4122                                                                 fadestart=atof(mapname);
4123
4124                                                                 donesomething=1;
4125                                                         }
4126
4127                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
4128                                                                 for(j=6;j<consolechars[0];j++){
4129                                                                         mapname[j-6]=consoletext[0][j];
4130                                                                 }
4131
4132                                                                 player[0].power=atof(mapname);
4133
4134                                                                 donesomething=1;
4135                                                         }
4136
4137                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
4138                                                                 for(j=6;j<consolechars[0];j++){
4139                                                                         mapname[j-6]=consoletext[0][j];
4140                                                                 }
4141
4142                                                                 slomospeed=atof(mapname);
4143                                                                 slomo=1-slomo;
4144                                                                 slomodelay=1000;
4145
4146                                                                 donesomething=1;
4147                                                         }
4148
4149                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
4150                                                                 for(j=8;j<consolechars[0];j++){
4151                                                                         mapname[j-8]=consoletext[0][j];
4152                                                                 }
4153
4154                                                                 slomofreq=atoi(mapname);
4155
4156                                                                 donesomething=1;
4157                                                         }
4158
4159                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
4160                                                                 for(j=5;j<consolechars[0];j++){
4161                                                                         mapname[j-5]=consoletext[0][j];
4162                                                                 }
4163
4164                                                                 player[0].scale=atof(mapname)*.2;
4165
4166                                                                 donesomething=1;
4167                                                         }
4168
4169                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
4170                                                                 int closest=-1;
4171                                                                 float closestdist=-1;
4172                                                                 float distance;
4173                                                                 if(numplayers>1)
4174                                                                         for(i=1;i<numplayers;i++){
4175                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4176                                                                                 if(closestdist==-1||distance<closestdist){
4177                                                                                         closestdist=distance;
4178                                                                                         closest=i;
4179                                                                                 }
4180                                                                         }
4181
4182                                                                         for(j=9;j<consolechars[0];j++){
4183                                                                                 mapname[j-9]=consoletext[0][j];
4184                                                                         }
4185
4186                                                                         player[closest].scale=atof(mapname)*.2;
4187
4188                                                                         donesomething=1;
4189                                                         }
4190
4191                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
4192                                                                 int startpoint;
4193                                                                 int alldone;
4194
4195                                                                 int closest=-1;
4196                                                                 float closestdist=-1;
4197                                                                 float distance;
4198                                                                 if(numplayers>1)
4199                                                                         for(i=1;i<numplayers;i++){
4200                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4201                                                                                 if(closestdist==-1||distance<closestdist){
4202                                                                                         closestdist=distance;
4203                                                                                         closest=i;
4204                                                                                 }
4205                                                                         }
4206
4207                                                                         alldone=0;
4208                                                                         startpoint=15;
4209                                                                         j=startpoint;
4210                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4211                                                                                 mapname[j-startpoint]=consoletext[0][j];
4212                                                                                 j++;
4213                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4214                                                                         }
4215                                                                         mapname[j-startpoint]='\0';
4216
4217                                                                         headprop=atof(mapname);
4218
4219                                                                         j++;
4220                                                                         startpoint=j;
4221                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4222                                                                                 mapname[j-startpoint]=consoletext[0][j];
4223                                                                                 j++;
4224                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4225                                                                         }
4226                                                                         mapname[j-startpoint]='\0';
4227
4228                                                                         bodyprop=atof(mapname);
4229
4230                                                                         j++;
4231                                                                         startpoint=j;
4232                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4233                                                                                 mapname[j-startpoint]=consoletext[0][j];
4234                                                                                 j++;
4235                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4236                                                                         }
4237                                                                         mapname[j-startpoint]='\0';
4238
4239                                                                         armprop=atof(mapname);
4240
4241                                                                         j++;
4242                                                                         startpoint=j;
4243                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4244                                                                                 mapname[j-startpoint]=consoletext[0][j];
4245                                                                                 j++;
4246                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4247                                                                         }
4248                                                                         mapname[j-startpoint]='\0';
4249
4250                                                                         legprop=atof(mapname);
4251
4252                                                                         if(player[closest].creature==wolftype){
4253                                                                                 player[closest].proportionhead=1.1*headprop;
4254                                                                                 player[closest].proportionbody=1.1*bodyprop;
4255                                                                                 player[closest].proportionarms=1.1*armprop;
4256                                                                                 player[closest].proportionlegs=1.1*legprop;
4257                                                                         }
4258
4259                                                                         if(player[closest].creature==rabbittype){
4260                                                                                 player[closest].proportionhead=1.2*headprop;
4261                                                                                 player[closest].proportionbody=1.05*bodyprop;
4262                                                                                 player[closest].proportionarms=1.00*armprop;
4263                                                                                 player[closest].proportionlegs=1.1*legprop;
4264                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4265                                                                         }
4266
4267                                                                         donesomething=1;
4268                                                         }
4269
4270
4271                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4272                                                                 for(i=1;i<numplayers;i++){
4273                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4274                                                                 }
4275
4276                                                                 donesomething=1;
4277                                                         }
4278
4279                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4280                                                                 for(j=9;j<consolechars[0];j++){
4281                                                                         mapname[j-9]=consoletext[0][j];
4282                                                                 }
4283
4284                                                                 tutoriallevel=atoi(mapname);
4285
4286                                                                 donesomething=1;
4287                                                         }
4288
4289
4290                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4291                                                                 for(j=6;j<consolechars[0];j++){
4292                                                                         mapname[j-6]=consoletext[0][j];
4293                                                                 }
4294
4295                                                                 tintg=atof(mapname);
4296
4297                                                                 donesomething=1;
4298                                                         }
4299
4300                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4301                                                                 for(j=6;j<consolechars[0];j++){
4302                                                                         mapname[j-6]=consoletext[0][j];
4303                                                                 }
4304
4305                                                                 tintb=atof(mapname);
4306
4307                                                                 donesomething=1;
4308                                                         }
4309
4310                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4311                                                                 for(j=8;j<consolechars[0];j++){
4312                                                                         mapname[j-8]=consoletext[0][j];
4313                                                                 }
4314
4315                                                                 hostile=atoi(mapname);
4316
4317                                                                 donesomething=1;
4318                                                         }
4319
4320
4321                                                         if(Compare(consoletext[0],"type active ",0,11)){
4322                                                                 editoractive=typeactive;
4323
4324                                                                 donesomething=1;
4325                                                         }
4326
4327                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4328                                                                 indemo=1;
4329                                                                 hotspot[numhotspots]=player[0].coords;
4330                                                                 hotspotsize[numhotspots]=0;
4331                                                                 hotspottype[numhotspots]=-111;
4332                                                                 mapname[0]='\0';
4333                                                                 strcpy(hotspottext[numhotspots],"mapname");
4334                                                                 numhotspots++;
4335
4336                                                                 donesomething=1;
4337                                                         }
4338
4339                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4340                                                                 indemo=0;
4341                                                                 numhotspots--;
4342
4343                                                                 donesomething=1;
4344                                                         }
4345
4346                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4347                                                                 editoractive=typesitting;
4348
4349                                                                 donesomething=1;
4350                                                         }
4351
4352                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4353                                                                 editoractive=typesittingwall;
4354
4355                                                                 donesomething=1;
4356                                                         }
4357
4358                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4359                                                                 editoractive=typesleeping;
4360
4361                                                                 donesomething=1;
4362                                                         }
4363                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4364                                                                 editoractive=typedead1;
4365
4366                                                                 donesomething=1;
4367                                                         }
4368                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4369                                                                 editoractive=typedead2;
4370
4371                                                                 donesomething=1;
4372                                                         }
4373                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4374                                                                 editoractive=typedead3;
4375                                                                 donesomething=1;
4376                                                         }
4377                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4378                                                                 editoractive=typedead4;
4379
4380                                                                 donesomething=1;
4381                                                         }
4382
4383                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4384                                                                 editorpathtype=wpkeepwalking;
4385
4386                                                                 donesomething=1;
4387                                                         }
4388
4389                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4390                                                                 editorpathtype=wppause;
4391
4392                                                                 donesomething=1;
4393                                                         }
4394
4395                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4396                                                                 maptype=mapkilleveryone;
4397
4398                                                                 donesomething=1;
4399                                                         }
4400
4401                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4402                                                                 maptype=mapgosomewhere;
4403
4404                                                                 donesomething=1;
4405                                                         }
4406
4407                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4408                                                                 maptype=mapkillsomeone;
4409
4410                                                                 donesomething=1;
4411
4412                                                         }
4413
4414                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4415                                                                 maptype=mapkillmost;
4416
4417                                                                 donesomething=1;
4418
4419                                                         }
4420
4421                                                         if(Compare(consoletext[0],"hs ",0,2)){
4422                                                                 int startpoint;
4423                                                                 int alldone;
4424
4425                                                                 hotspot[numhotspots]=player[0].coords;
4426
4427                                                                 alldone=0;
4428                                                                 startpoint=3;
4429                                                                 j=startpoint;
4430                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4431                                                                         mapname[j-startpoint]=consoletext[0][j];
4432                                                                         j++;
4433                                                                         if(consoletext[0][j]=='\0')alldone=1;
4434                                                                 }
4435                                                                 mapname[j-startpoint]='\0';
4436
4437                                                                 hotspotsize[numhotspots]=atof(mapname);
4438
4439                                                                 j++;
4440                                                                 startpoint=j;
4441                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4442                                                                         mapname[j-startpoint]=consoletext[0][j];
4443                                                                         j++;
4444                                                                         if(consoletext[0][j]=='\0')alldone=1;
4445                                                                 }
4446                                                                 mapname[j-startpoint]='\0';
4447
4448                                                                 hotspottype[numhotspots]=atoi(mapname);
4449
4450                                                                 j++;
4451                                                                 startpoint=j;
4452                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4453                                                                         mapname[j-startpoint]=consoletext[0][j];
4454                                                                         j++;
4455                                                                         if(consoletext[0][j]=='\0')alldone=1;
4456                                                                 }
4457                                                                 mapname[j-startpoint]='\n';
4458                                                                 mapname[j-startpoint+1]='\0';
4459
4460                                                                 strcpy(hotspottext[numhotspots],mapname);
4461
4462                                                                 numhotspots++;
4463
4464                                                                 donesomething=1;
4465                                                         }
4466
4467                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4468                                                                 int startpoint;
4469                                                                 int alldone;
4470
4471                                                                 alldone=0;
4472                                                                 startpoint=9;
4473                                                                 j=startpoint;
4474                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4475                                                                         mapname[j-startpoint]=consoletext[0][j];
4476                                                                         j++;
4477                                                                         if(consoletext[0][j]=='\0')alldone=1;
4478                                                                 }
4479                                                                 mapname[j-startpoint]='\0';
4480                                                                 startpoint=j+1;
4481
4482                                                                 dialoguetype[numdialogues]=atoi(mapname);
4483
4484                                                                 mapname[0]=':';
4485                                                                 mapname[1]='D';
4486                                                                 mapname[2]='a';
4487                                                                 mapname[3]='t';
4488                                                                 mapname[4]='a';
4489                                                                 mapname[5]=':';
4490                                                                 mapname[6]='D';
4491                                                                 mapname[7]='i';
4492                                                                 mapname[8]='a';
4493                                                                 mapname[9]='l';
4494                                                                 mapname[10]='o';
4495                                                                 mapname[11]='g';
4496                                                                 mapname[12]='u';
4497                                                                 mapname[13]='e';
4498                                                                 mapname[14]='s';
4499                                                                 mapname[15]=':';
4500                                                                 for(j=startpoint;j<consolechars[0];j++){
4501                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4502                                                                 }
4503                                                                 mapname[consolechars[0]-startpoint+16]='.';
4504                                                                 mapname[consolechars[0]-startpoint+17]='t';
4505                                                                 mapname[consolechars[0]-startpoint+18]='x';
4506                                                                 mapname[consolechars[0]-startpoint+19]='t';
4507                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4508
4509                                                                 for(j=0;j<max_dialoguelength;j++){
4510                                                                         for(k=0;k<128;k++){
4511                                                                                 dialoguetext[numdialogues][j][k]='\0';
4512                                                                         }
4513                                                                         for(k=0;k<64;k++){
4514                                                                                 dialoguename[numdialogues][j][k]='\0';
4515                                                                         }
4516                                                                 }
4517
4518                                                                 ifstream ipstream(ConvertFileName(mapname));
4519                                                                 ipstream.ignore(256,':');
4520                                                                 ipstream >> numdialogueboxes[numdialogues];
4521                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4522                                                                         ipstream.ignore(256,':');
4523                                                                         ipstream.ignore(256,':');
4524                                                                         ipstream.ignore(256,' ');
4525                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4526                                                                         ipstream.ignore(256,':');
4527                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4528                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4529                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4530                                                                         ipstream.ignore(256,':');
4531                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4532                                                                         ipstream.ignore(256,':');
4533                                                                         ipstream.ignore(256,' ');
4534                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4535                                                                         for(j=0;j<128;j++){
4536                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4537                                                                         }
4538                                                                         ipstream.ignore(256,':');
4539                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4540                                                                 }
4541
4542                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4543                                                                         for(j=0;j<numplayers;j++){
4544                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4545                                                                         }
4546                                                                 }
4547                                                                 ipstream.close();
4548
4549                                                                 directing=1;
4550                                                                 indialogue=0;
4551                                                                 whichdialogue=numdialogues;
4552
4553
4554                                                                 numdialogues++;
4555
4556                                                                 donesomething=1;
4557                                                         }
4558
4559                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4560                                                                 int startpoint;
4561                                                                 int alldone;
4562                                                                 int whichdi;
4563
4564                                                                 alldone=0;
4565                                                                 startpoint=12;
4566                                                                 j=startpoint;
4567                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4568                                                                         mapname[j-startpoint]=consoletext[0][j];
4569                                                                         j++;
4570                                                                         if(consoletext[0][j]=='\0')alldone=1;
4571                                                                 }
4572                                                                 mapname[j-startpoint]='\0';
4573                                                                 startpoint=j+1;
4574
4575                                                                 whichdi=atoi(mapname);
4576
4577                                                                 mapname[0]=':';
4578                                                                 mapname[1]='D';
4579                                                                 mapname[2]='a';
4580                                                                 mapname[3]='t';
4581                                                                 mapname[4]='a';
4582                                                                 mapname[5]=':';
4583                                                                 mapname[6]='D';
4584                                                                 mapname[7]='i';
4585                                                                 mapname[8]='a';
4586                                                                 mapname[9]='l';
4587                                                                 mapname[10]='o';
4588                                                                 mapname[11]='g';
4589                                                                 mapname[12]='u';
4590                                                                 mapname[13]='e';
4591                                                                 mapname[14]='s';
4592                                                                 mapname[15]=':';
4593                                                                 for(j=startpoint;j<consolechars[0];j++){
4594                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4595                                                                 }
4596                                                                 mapname[consolechars[0]-startpoint+16]='.';
4597                                                                 mapname[consolechars[0]-startpoint+17]='t';
4598                                                                 mapname[consolechars[0]-startpoint+18]='x';
4599                                                                 mapname[consolechars[0]-startpoint+19]='t';
4600                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4601
4602                                                                 for(j=0;j<max_dialoguelength;j++){
4603                                                                         for(k=0;k<128;k++){
4604                                                                                 dialoguetext[whichdi][j][k]='\0';
4605                                                                         }
4606                                                                         for(k=0;k<64;k++){
4607                                                                                 dialoguename[whichdi][j][k]='\0';
4608                                                                         }
4609                                                                 }
4610
4611                                                                 ifstream ipstream(ConvertFileName(mapname));
4612                                                                 ipstream.ignore(256,':');
4613                                                                 ipstream >> numdialogueboxes[whichdi];
4614                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4615                                                                         ipstream.ignore(256,':');
4616                                                                         ipstream.ignore(256,':');
4617                                                                         ipstream.ignore(256,' ');
4618                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4619                                                                         ipstream.ignore(256,':');
4620                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4621                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4622                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4623                                                                         ipstream.ignore(256,':');
4624                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4625                                                                         ipstream.ignore(256,':');
4626                                                                         ipstream.ignore(256,' ');
4627                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4628                                                                         for(j=0;j<128;j++){
4629                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4630                                                                         }
4631                                                                         ipstream.ignore(256,':');
4632                                                                         ipstream >> dialogueboxsound[whichdi][i];
4633                                                                 }
4634
4635                                                                 ipstream.close();
4636
4637                                                                 donesomething=1;
4638                                                         }
4639
4640                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4641                                                                 int startpoint;
4642                                                                 int alldone;
4643                                                                 int whichdi;
4644
4645                                                                 alldone=0;
4646                                                                 startpoint=8;
4647                                                                 j=startpoint;
4648                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4649                                                                         mapname[j-startpoint]=consoletext[0][j];
4650                                                                         j++;
4651                                                                         if(consoletext[0][j]=='\0')alldone=1;
4652                                                                 }
4653                                                                 mapname[j-startpoint]='\0';
4654                                                                 dialoguetype[0]=atoi(mapname);
4655
4656                                                                 startpoint=j+1;
4657
4658                                                                 donesomething=1;
4659                                                         }
4660
4661
4662                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4663                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4664
4665                                                                 donesomething=1;
4666                                                         }
4667
4668                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4669                                                                 numdialogues--;
4670                                                                 if(numdialogues<0)numdialogues=0;
4671
4672                                                                 donesomething=1;
4673                                                         }
4674
4675                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4676                                                                 player[0].immobile=1;
4677                                                                 donesomething=1;
4678                                                         }
4679
4680                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4681                                                                 player[0].immobile=0;
4682                                                                 donesomething=1;
4683                                                         }
4684
4685                                                         if(Compare(consoletext[0],"play ",0,4)){
4686                                                                 int startpoint;
4687                                                                 int alldone;
4688
4689                                                                 alldone=0;
4690                                                                 startpoint=5;
4691                                                                 j=startpoint;
4692                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4693                                                                         mapname[j-startpoint]=consoletext[0][j];
4694                                                                         j++;
4695                                                                         if(consoletext[0][j]=='\0')alldone=1;
4696                                                                 }
4697                                                                 mapname[j-startpoint]='\0';
4698                                                                 startpoint=j+1;
4699
4700                                                                 whichdialogue=atoi(mapname);
4701
4702                                                                 if(numdialogues>whichdialogue){
4703                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4704                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4705                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4706                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4707                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4708                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4709                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4710                                                                         }
4711
4712                                                                         directing=0;
4713                                                                         indialogue=0;
4714
4715                                                                         donesomething=1;
4716
4717                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4718                                                                         float gLoc[3];
4719                                                                         float vel[3];
4720                                                                         XYZ temppos;
4721                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4722                                                                         temppos=temppos-viewer;
4723                                                                         Normalise(&temppos);
4724                                                                         temppos+=viewer;
4725
4726                                                                         gLoc[0]=temppos.x;
4727                                                                         gLoc[1]=temppos.y;
4728                                                                         gLoc[2]=temppos.z;
4729                                                                         vel[0]=0;
4730                                                                         vel[1]=0;
4731                                                                         vel[2]=0;
4732                                                                         int whichsoundplay;
4733                                                                         whichsoundplay=rabbitchitter;
4734                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4735                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4736                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4737                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4738                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4739                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4740                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4741                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4742                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4743                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4744                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4745                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4746                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4747                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4748                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4749                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4750                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4751                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4752                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4753                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
4754                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4755                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
4756                                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
4757                                                                         //}
4758                                                                 }
4759                                                         }
4760
4761
4762
4763
4764                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4765                                                                 numhotspots--;
4766                                                                 if(numhotspots<0)numhotspots=0;
4767                                                                 donesomething=1;
4768                                                         }
4769
4770
4771                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4772                                                                 int startpoint;
4773                                                                 int alldone;
4774
4775                                                                 alldone=0;
4776                                                                 startpoint=11;
4777                                                                 j=startpoint;
4778                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4779                                                                         mapname[j-startpoint]=consoletext[0][j];
4780                                                                         j++;
4781                                                                         if(consoletext[0][j]=='\0')alldone=1;
4782                                                                 }
4783                                                                 mapname[j-startpoint]='\0';
4784
4785                                                                 headprop=atof(mapname);
4786
4787                                                                 j++;
4788                                                                 startpoint=j;
4789                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4790                                                                         mapname[j-startpoint]=consoletext[0][j];
4791                                                                         j++;
4792                                                                         if(consoletext[0][j]=='\0')alldone=1;
4793                                                                 }
4794                                                                 mapname[j-startpoint]='\0';
4795
4796                                                                 bodyprop=atof(mapname);
4797
4798                                                                 j++;
4799                                                                 startpoint=j;
4800                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4801                                                                         mapname[j-startpoint]=consoletext[0][j];
4802                                                                         j++;
4803                                                                         if(consoletext[0][j]=='\0')alldone=1;
4804                                                                 }
4805                                                                 mapname[j-startpoint]='\0';
4806
4807                                                                 armprop=atof(mapname);
4808
4809                                                                 j++;
4810                                                                 startpoint=j;
4811                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4812                                                                         mapname[j-startpoint]=consoletext[0][j];
4813                                                                         j++;
4814                                                                         if(consoletext[0][j]=='\0')alldone=1;
4815                                                                 }
4816                                                                 mapname[j-startpoint]='\0';
4817
4818                                                                 legprop=atof(mapname);
4819
4820                                                                 if(player[0].creature==wolftype){
4821                                                                         player[0].proportionhead=1.1*headprop;
4822                                                                         player[0].proportionbody=1.1*bodyprop;
4823                                                                         player[0].proportionarms=1.1*armprop;
4824                                                                         player[0].proportionlegs=1.1*legprop;
4825                                                                 }
4826
4827                                                                 if(player[0].creature==rabbittype){
4828                                                                         player[0].proportionhead=1.2*headprop;
4829                                                                         player[0].proportionbody=1.05*bodyprop;
4830                                                                         player[0].proportionarms=1.00*armprop;
4831                                                                         player[0].proportionlegs=1.1*legprop;
4832                                                                         player[0].proportionlegs.y=1.05*legprop;
4833                                                                 }
4834
4835                                                                 donesomething=1;
4836                                                         }
4837
4838                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4839                                                                 for(i=0;i<numplayers;i++){
4840                                                                         if(i>0)player[i].immobile=1;
4841                                                                 }
4842                                                                 donesomething=1;
4843                                                         }
4844
4845
4846                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4847                                                                 player[0].armorhead=1;
4848                                                                 player[0].armorhigh=1;
4849                                                                 player[0].armorlow=1;
4850                                                                 player[0].protectionhead=1;
4851                                                                 player[0].protectionhigh=1;
4852                                                                 player[0].protectionlow=1;
4853                                                                 player[0].metalhead=1;
4854                                                                 player[0].metalhigh=1;
4855                                                                 player[0].metallow=1;
4856                                                                 player[0].power=1;
4857                                                                 player[0].speedmult=1;
4858                                                                 player[0].scale=1;
4859
4860                                                                 if(player[0].creature==wolftype){
4861                                                                         player[0].proportionhead=1.1;
4862                                                                         player[0].proportionbody=1.1;
4863                                                                         player[0].proportionarms=1.1;
4864                                                                         player[0].proportionlegs=1.1;
4865                                                                 }
4866
4867                                                                 if(player[0].creature==rabbittype){
4868                                                                         player[0].proportionhead=1.2;
4869                                                                         player[0].proportionbody=1.05;
4870                                                                         player[0].proportionarms=1.00;
4871                                                                         player[0].proportionlegs=1.1;
4872                                                                         player[0].proportionlegs.y=1.05;
4873                                                                 }
4874
4875                                                                 player[0].numclothes=0;
4876                                                                 if(player[0].whichskin==0){
4877                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4878                                                                 }
4879                                                                 else if(player[0].whichskin==1){
4880                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4881                                                                 }
4882                                                                 else if(player[0].whichskin==2){
4883                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4884                                                                 }
4885                                                                 else if(player[0].whichskin==3){
4886                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4887                                                                 }
4888                                                                 else if(player[0].whichskin==4){
4889                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4890                                                                 }
4891                                                                 else if(player[0].whichskin==5){
4892                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4893                                                                 }
4894                                                                 else if(player[0].whichskin==6){
4895                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4896                                                                 }
4897                                                                 else if(player[0].whichskin==7){
4898                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4899                                                                 }
4900                                                                 else if(player[0].whichskin==8){
4901                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4902                                                                 }
4903                                                                 else if(player[0].whichskin==9){
4904                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4905                                                                 }
4906
4907                                                                 editoractive=typeactive;
4908                                                                 player[0].immobile=0;
4909
4910
4911
4912                                                                 donesomething=1;
4913                                                         }
4914
4915                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4916                                                                 int startpoint;
4917                                                                 int alldone;
4918                                                                 alldone=0;
4919                                                                 startpoint=5;
4920                                                                 j=startpoint;
4921                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4922                                                                         mapname[j-startpoint]=consoletext[0][j];
4923                                                                         j++;
4924                                                                         if(consoletext[0][j]=='\0')alldone=1;
4925                                                                 }
4926                                                                 mapname[j-startpoint]='\0';
4927
4928                                                                 tintr=atof(mapname);
4929
4930                                                                 j++;
4931                                                                 startpoint=j;
4932                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4933                                                                         mapname[j-startpoint]=consoletext[0][j];
4934                                                                         j++;
4935                                                                         if(consoletext[0][j]=='\0')alldone=1;
4936                                                                 }
4937                                                                 mapname[j-startpoint]='\0';
4938
4939                                                                 tintg=atof(mapname);
4940
4941                                                                 j++;
4942                                                                 startpoint=j;
4943                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4944                                                                         mapname[j-startpoint]=consoletext[0][j];
4945                                                                         j++;
4946                                                                         if(consoletext[0][j]=='\0')alldone=1;
4947                                                                 }
4948                                                                 mapname[j-startpoint]='\0';
4949
4950                                                                 tintb=atof(mapname);
4951
4952                                                                 donesomething=1;
4953                                                         }
4954
4955                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
4956                                                                 int startpoint;
4957                                                                 int alldone;
4958                                                                 alldone=0;
4959                                                                 startpoint=9;
4960                                                                 j=startpoint;
4961                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4962                                                                         mapname[j-startpoint]=consoletext[0][j];
4963                                                                         j++;
4964                                                                         if(consoletext[0][j]=='\0')alldone=1;
4965                                                                 }
4966                                                                 mapname[j-startpoint]='\0';
4967
4968                                                                 skyboxr=atof(mapname);
4969
4970                                                                 j++;
4971                                                                 startpoint=j;
4972                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4973                                                                         mapname[j-startpoint]=consoletext[0][j];
4974                                                                         j++;
4975                                                                         if(consoletext[0][j]=='\0')alldone=1;
4976                                                                 }
4977                                                                 mapname[j-startpoint]='\0';
4978
4979                                                                 skyboxg=atof(mapname);
4980
4981                                                                 j++;
4982                                                                 startpoint=j;
4983                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4984                                                                         mapname[j-startpoint]=consoletext[0][j];
4985                                                                         j++;
4986                                                                         if(consoletext[0][j]=='\0')alldone=1;
4987                                                                 }
4988                                                                 mapname[j-startpoint]='\0';
4989
4990                                                                 skyboxb=atof(mapname);
4991
4992                                                                 skyboxlightr=skyboxr;
4993                                                                 skyboxlightg=skyboxg;
4994                                                                 skyboxlightb=skyboxb;
4995
4996                                                                 SetUpLighting();
4997
4998                                                                 //if(skyboxtexture){
4999                                                                 terrain.DoShadows();
5000                                                                 objects.DoShadows();
5001                                                                 /*}
5002                                                                 else terrain.DoLighting();
5003                                                                 */
5004                                                                 donesomething=1;
5005                                                         } 
5006
5007                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
5008                                                                 int startpoint;
5009                                                                 int alldone;
5010                                                                 alldone=0;
5011                                                                 startpoint=10;
5012                                                                 j=startpoint;
5013                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5014                                                                         mapname[j-startpoint]=consoletext[0][j];
5015                                                                         j++;
5016                                                                         if(consoletext[0][j]=='\0')alldone=1;
5017                                                                 }
5018                                                                 mapname[j-startpoint]='\0';
5019
5020                                                                 skyboxlightr=atof(mapname);
5021
5022                                                                 j++;
5023                                                                 startpoint=j;
5024                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5025                                                                         mapname[j-startpoint]=consoletext[0][j];
5026                                                                         j++;
5027                                                                         if(consoletext[0][j]=='\0')alldone=1;
5028                                                                 }
5029                                                                 mapname[j-startpoint]='\0';
5030
5031                                                                 skyboxlightg=atof(mapname);
5032
5033                                                                 j++;
5034                                                                 startpoint=j;
5035                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5036                                                                         mapname[j-startpoint]=consoletext[0][j];
5037                                                                         j++;
5038                                                                         if(consoletext[0][j]=='\0')alldone=1;
5039                                                                 }
5040                                                                 mapname[j-startpoint]='\0';
5041
5042                                                                 skyboxlightb=atof(mapname);
5043
5044                                                                 SetUpLighting();
5045
5046                                                                 //if(skyboxtexture){
5047                                                                 terrain.DoShadows();
5048                                                                 objects.DoShadows();
5049                                                                 /*}
5050                                                                 else terrain.DoLighting();
5051                                                                 */
5052                                                                 donesomething=1;
5053                                                         } 
5054
5055                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
5056                                                                 skyboxtexture=1-skyboxtexture;
5057
5058                                                                 SetUpLighting();
5059                                                                 //if(skyboxtexture){
5060                                                                 terrain.DoShadows();
5061                                                                 objects.DoShadows();
5062                                                                 /*}
5063                                                                 else terrain.DoLighting();
5064                                                                 */
5065                                                                 donesomething=1;
5066                                                         }
5067
5068                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
5069                                                                 int startpoint;
5070                                                                 int alldone;
5071                                                                 alldone=0;
5072                                                                 startpoint=11;
5073                                                                 j=startpoint;
5074                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5075                                                                         mapname[j-startpoint]=consoletext[0][j];
5076                                                                         j++;
5077                                                                         if(consoletext[0][j]=='\0')alldone=1;
5078                                                                 }
5079                                                                 mapname[j-startpoint]='\0';
5080
5081                                                                 player[0].protectionhead=atof(mapname);
5082
5083                                                                 j++;
5084                                                                 startpoint=j;
5085                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5086                                                                         mapname[j-startpoint]=consoletext[0][j];
5087                                                                         j++;
5088                                                                         if(consoletext[0][j]=='\0')alldone=1;
5089                                                                 }
5090                                                                 mapname[j-startpoint]='\0';
5091
5092                                                                 player[0].protectionhigh=atof(mapname);
5093
5094                                                                 j++;
5095                                                                 startpoint=j;
5096                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5097                                                                         mapname[j-startpoint]=consoletext[0][j];
5098                                                                         j++;
5099                                                                         if(consoletext[0][j]=='\0')alldone=1;
5100                                                                 }
5101                                                                 mapname[j-startpoint]='\0';
5102
5103                                                                 player[0].protectionlow=atof(mapname);
5104
5105                                                                 donesomething=1;
5106                                                         }
5107
5108                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
5109                                                                 int startpoint;
5110                                                                 int alldone;
5111                                                                 alldone=0;
5112                                                                 startpoint=6;
5113                                                                 j=startpoint;
5114                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5115                                                                         mapname[j-startpoint]=consoletext[0][j];
5116                                                                         j++;
5117                                                                         if(consoletext[0][j]=='\0')alldone=1;
5118                                                                 }
5119                                                                 mapname[j-startpoint]='\0';
5120
5121                                                                 player[0].armorhead=atof(mapname);
5122
5123                                                                 j++;
5124                                                                 startpoint=j;
5125                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5126                                                                         mapname[j-startpoint]=consoletext[0][j];
5127                                                                         j++;
5128                                                                         if(consoletext[0][j]=='\0')alldone=1;
5129                                                                 }
5130                                                                 mapname[j-startpoint]='\0';
5131
5132                                                                 player[0].armorhigh=atof(mapname);
5133
5134                                                                 j++;
5135                                                                 startpoint=j;
5136                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5137                                                                         mapname[j-startpoint]=consoletext[0][j];
5138                                                                         j++;
5139                                                                         if(consoletext[0][j]=='\0')alldone=1;
5140                                                                 }
5141                                                                 mapname[j-startpoint]='\0';
5142
5143                                                                 player[0].armorlow=atof(mapname);
5144
5145                                                                 donesomething=1;
5146                                                         }
5147
5148                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
5149                                                                 for(i=0;i<numplayers;i++){
5150                                                                         player[i].protectionhead=1.0;
5151                                                                         player[i].protectionhigh=1.0;
5152                                                                         player[i].protectionlow=1.0;
5153                                                                         player[i].armorhead=1.0;
5154                                                                         player[i].armorhigh=1.0;
5155                                                                         player[i].armorlow=1.0;
5156                                                                 }
5157
5158                                                                 donesomething=1;
5159                                                         }
5160
5161                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
5162                                                                 int closest=-1;
5163                                                                 float closestdist=-1;
5164                                                                 float distance;
5165                                                                 if(numplayers>1)
5166                                                                         for(i=1;i<numplayers;i++){
5167                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5168                                                                                 if(closestdist==-1||distance<closestdist){
5169                                                                                         closestdist=distance;
5170                                                                                         closest=i;
5171                                                                                 }
5172                                                                         }
5173
5174                                                                         int startpoint;
5175                                                                         int alldone;
5176                                                                         alldone=0;
5177                                                                         startpoint=15;
5178                                                                         j=startpoint;
5179                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5180                                                                                 mapname[j-startpoint]=consoletext[0][j];
5181                                                                                 j++;
5182                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5183                                                                         }
5184                                                                         mapname[j-startpoint]='\0';
5185
5186                                                                         player[closest].protectionhead=atof(mapname);
5187
5188                                                                         j++;
5189                                                                         startpoint=j;
5190                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5191                                                                                 mapname[j-startpoint]=consoletext[0][j];
5192                                                                                 j++;
5193                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5194                                                                         }
5195                                                                         mapname[j-startpoint]='\0';
5196
5197                                                                         player[closest].protectionhigh=atof(mapname);
5198
5199                                                                         j++;
5200                                                                         startpoint=j;
5201                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5202                                                                                 mapname[j-startpoint]=consoletext[0][j];
5203                                                                                 j++;
5204                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5205                                                                         }
5206                                                                         mapname[j-startpoint]='\0';
5207
5208                                                                         player[closest].protectionlow=atof(mapname);
5209
5210                                                                         donesomething=1;
5211                                                         }
5212
5213                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
5214                                                                 int closest=-1;
5215                                                                 float closestdist=-1;
5216                                                                 float distance;
5217                                                                 if(numplayers>1)
5218                                                                         for(i=1;i<numplayers;i++){
5219                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5220                                                                                 if(closestdist==-1||distance<closestdist){
5221                                                                                         closestdist=distance;
5222                                                                                         closest=i;
5223                                                                                 }
5224                                                                         }
5225                                                                         int startpoint;
5226                                                                         int alldone;
5227                                                                         alldone=0;
5228                                                                         startpoint=10;
5229                                                                         j=startpoint;
5230                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5231                                                                                 mapname[j-startpoint]=consoletext[0][j];
5232                                                                                 j++;
5233                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5234                                                                         }
5235                                                                         mapname[j-startpoint]='\0';
5236
5237                                                                         player[closest].armorhead=atof(mapname);
5238
5239                                                                         j++;
5240                                                                         startpoint=j;
5241                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5242                                                                                 mapname[j-startpoint]=consoletext[0][j];
5243                                                                                 j++;
5244                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5245                                                                         }
5246                                                                         mapname[j-startpoint]='\0';
5247
5248                                                                         player[closest].armorhigh=atof(mapname);
5249
5250                                                                         j++;
5251                                                                         startpoint=j;
5252                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5253                                                                                 mapname[j-startpoint]=consoletext[0][j];
5254                                                                                 j++;
5255                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5256                                                                         }
5257                                                                         mapname[j-startpoint]='\0';
5258
5259                                                                         player[closest].armorlow=atof(mapname);
5260
5261                                                                         donesomething=1;
5262                                                         }
5263
5264
5265                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5266                                                                 int startpoint;
5267                                                                 int alldone;
5268                                                                 alldone=0;
5269                                                                 startpoint=6;
5270                                                                 j=startpoint;
5271                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5272                                                                         mapname[j-startpoint]=consoletext[0][j];
5273                                                                         j++;
5274                                                                         if(consoletext[0][j]=='\0')alldone=1;
5275                                                                 }
5276                                                                 mapname[j-startpoint]='\0';
5277
5278                                                                 player[0].metalhead=atof(mapname);
5279
5280                                                                 j++;
5281                                                                 startpoint=j;
5282                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5283                                                                         mapname[j-startpoint]=consoletext[0][j];
5284                                                                         j++;
5285                                                                         if(consoletext[0][j]=='\0')alldone=1;
5286                                                                 }
5287                                                                 mapname[j-startpoint]='\0';
5288
5289                                                                 player[0].metalhigh=atof(mapname);
5290
5291                                                                 j++;
5292                                                                 startpoint=j;
5293                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5294                                                                         mapname[j-startpoint]=consoletext[0][j];
5295                                                                         j++;
5296                                                                         if(consoletext[0][j]=='\0')alldone=1;
5297                                                                 }
5298
5299                                                                 mapname[j-startpoint]='\0';
5300
5301                                                                 player[0].metallow=atof(mapname);
5302
5303                                                                 donesomething=1;
5304                                                         }
5305
5306                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5307                                                                 int closest=-1;
5308                                                                 float closestdist=-1;
5309                                                                 float distance;
5310                                                                 if(numplayers>1)
5311                                                                         for(i=1;i<numplayers;i++){
5312                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5313                                                                                 if(closestdist==-1||distance<closestdist){
5314                                                                                         closestdist=distance;
5315                                                                                         closest=i;
5316                                                                                 }
5317                                                                         }
5318                                                                         player[closest].numclothes=0;
5319                                                                         if(player[closest].whichskin==0){
5320                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5321                                                                         }
5322                                                                         else if(player[closest].whichskin==1){
5323                                                                                 LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5324                                                                         }
5325                                                                         else if(player[closest].whichskin==2){
5326                                                                                 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5327                                                                         }
5328                                                                         else if(player[closest].whichskin==3){
5329                                                                                 LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5330                                                                         }
5331                                                                         else if(player[closest].whichskin==4){
5332                                                                                 LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5333                                                                         }
5334                                                                         else if(player[closest].whichskin==5){
5335                                                                                 LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5336                                                                         }
5337                                                                         else if(player[closest].whichskin==6){
5338                                                                                 LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5339                                                                         }
5340                                                                         else if(player[closest].whichskin==7){
5341                                                                                 LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5342                                                                         }
5343                                                                         else if(player[closest].whichskin==8){
5344                                                                                 LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5345                                                                         }
5346                                                                         else if(player[closest].whichskin==9){
5347                                                                                 LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5348                                                                         }
5349
5350                                                                         donesomething=1;
5351                                                         }
5352
5353                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5354                                                                 int closest=0;
5355
5356                                                                 player[closest].numclothes=0;
5357                                                                 if(player[closest].whichskin==0){
5358                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5359                                                                 }
5360                                                                 else if(player[closest].whichskin==1){
5361                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5362                                                                 }
5363                                                                 else if(player[closest].whichskin==2){
5364                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5365                                                                 }
5366                                                                 else if(player[closest].whichskin==3){
5367                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5368                                                                 }
5369                                                                 else if(player[closest].whichskin==4){
5370                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5371                                                                 }
5372                                                                 else if(player[closest].whichskin==5){
5373                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5374                                                                 }
5375                                                                 else if(player[closest].whichskin==6){
5376                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5377                                                                 }
5378                                                                 else if(player[closest].whichskin==7){
5379                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5380                                                                 }
5381                                                                 else if(player[closest].whichskin==8){
5382                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5383                                                                 }
5384                                                                 else if(player[closest].whichskin==9){
5385                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5386                                                                 }
5387
5388                                                                 donesomething=1;
5389                                                         }
5390
5391                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5392                                                                 mapname[0]=':';
5393                                                                 mapname[1]='D';
5394                                                                 mapname[2]='a';
5395                                                                 mapname[3]='t';
5396                                                                 mapname[4]='a';
5397                                                                 mapname[5]=':';
5398                                                                 mapname[6]='T';
5399                                                                 mapname[7]='e';
5400                                                                 mapname[8]='x';
5401                                                                 mapname[9]='t';
5402                                                                 mapname[10]='u';
5403                                                                 mapname[11]='r';
5404                                                                 mapname[12]='e';
5405                                                                 mapname[13]='s';
5406                                                                 mapname[14]=':';
5407                                                                 for(j=8;j<consolechars[0];j++){
5408                                                                         mapname[j-8+15]=consoletext[0][j];
5409                                                                 }
5410                                                                 mapname[consolechars[0]-8+15]='.';
5411                                                                 mapname[consolechars[0]-8+16]='p';
5412                                                                 mapname[consolechars[0]-8+17]='n';
5413                                                                 mapname[consolechars[0]-8+18]='g';
5414                                                                 mapname[consolechars[0]-8+19]='\0';
5415
5416                                                                 //:Data:Textures:Pants.png
5417
5418                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5419                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5420                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5421                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5422                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5423                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5424                                                                         player[0].numclothes++;
5425                                                                 }
5426
5427                                                                 donesomething=1;
5428                                                         }
5429
5430                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5431                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5432
5433                                                                 donesomething=1;
5434                                                         }
5435
5436                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5437                                                                 cellophane=1-cellophane;
5438
5439                                                                 if(cellophane){
5440                                                                         for(i=0;i<numplayers;i++){
5441                                                                                 player[i].proportionhead.z=0;
5442                                                                                 player[i].proportionbody.z=0;
5443                                                                                 player[i].proportionarms.z=0;
5444                                                                                 player[i].proportionlegs.z=0;
5445                                                                         }
5446                                                                 }
5447
5448                                                                 if(!cellophane){
5449                                                                         for(i=0;i<numplayers;i++){
5450                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5451                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5452                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5453                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5454                                                                         }
5455                                                                 }
5456
5457                                                                 donesomething=1;
5458                                                         }
5459
5460                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5461                                                                 mapname[0]=':';
5462                                                                 mapname[1]='D';
5463                                                                 mapname[2]='a';
5464                                                                 mapname[3]='t';
5465                                                                 mapname[4]='a';
5466                                                                 mapname[5]=':';
5467                                                                 mapname[6]='T';
5468                                                                 mapname[7]='e';
5469                                                                 mapname[8]='x';
5470                                                                 mapname[9]='t';
5471                                                                 mapname[10]='u';
5472                                                                 mapname[11]='r';
5473                                                                 mapname[12]='e';
5474                                                                 mapname[13]='s';
5475                                                                 mapname[14]=':';
5476                                                                 for(j=12;j<consolechars[0];j++){
5477                                                                         mapname[j-12+15]=consoletext[0][j];
5478                                                                 }
5479                                                                 mapname[consolechars[0]-12+15]='.';
5480                                                                 mapname[consolechars[0]-12+16]='p';
5481                                                                 mapname[consolechars[0]-12+17]='n';
5482                                                                 mapname[consolechars[0]-12+18]='g';
5483                                                                 mapname[consolechars[0]-12+19]='\0';
5484
5485                                                                 //:Data:Textures:Pants.png
5486                                                                 int closest=-1;
5487                                                                 float closestdist=-1;
5488                                                                 float distance;
5489                                                                 if(numplayers>1)
5490                                                                         for(i=1;i<numplayers;i++){
5491                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5492                                                                                 if(closestdist==-1||distance<closestdist){
5493                                                                                         closestdist=distance;
5494                                                                                         closest=i;
5495                                                                                 }
5496                                                                         }
5497
5498                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5499                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5500                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5501                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5502                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5503                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5504                                                                                 player[closest].numclothes++;
5505                                                                         }
5506
5507                                                                         donesomething=1;
5508                                                         }
5509
5510                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5511                                                                 player[0].skeleton.id=0;
5512                                                                 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);
5513                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5514                                                                 player[0].creature=rabbittype;
5515                                                                 player[0].scale=.2;
5516
5517                                                                 player[0].proportionhead=1.2;
5518                                                                 player[0].proportionbody=1.05;
5519                                                                 player[0].proportionarms=1.00;
5520                                                                 player[0].proportionlegs=1.1;
5521                                                                 player[0].proportionlegs.y=1.05;
5522                                                                 player[0].headless=0;
5523
5524                                                                 player[0].damagetolerance=200;
5525
5526                                                                 donesomething=1;
5527                                                         }
5528                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5529                                                                 player[0].skeleton.id=0;
5530                                                                 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);
5531                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5532                                                                 player[0].creature=wolftype;
5533
5534                                                                 player[0].proportionhead=1.1;
5535                                                                 player[0].proportionbody=1.1;
5536                                                                 player[0].proportionarms=1.1;
5537                                                                 player[0].proportionlegs=1.1;
5538                                                                 player[0].proportionlegs.y=1.1;
5539                                                                 player[0].scale=.23;
5540
5541                                                                 player[0].damagetolerance=300;
5542
5543                                                                 donesomething=1;
5544                                                         }
5545                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5546                                                         LoadTextureSave(":Data:Textures:Kungfu.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],"rambo ",0,5)){
5550                                                         LoadTextureSave(":Data:Textures:Leather.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],"david ",0,5)){
5554                                                         LoadTextureSave(":Data:Textures:David.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],"wolf ",0,4)){
5558                                                                 LoadTextureSave(":Data:Textures:Wolf.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],"darkwolf ",0,8)){
5562                                                                 LoadTextureSave(":Data:Textures:DarkWolf.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],"snowwolf ",0,8)){
5566                                                                 LoadTextureSave(":Data:Textures:Snowwolf.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],"lizardwolf ",0,10)){
5570                                                          LoadTextureSave(":Data:Textures:Lizardwolf.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],"white ",0,5)){
5574                                                                 LoadTextureSave(":Data:Textures:fur.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],"brown ",0,5)){
5578                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5579                                                                 donesomething=1;
5580                                                         }
5581                                                         if(Compare(consoletext[0],"black ",0,5)){
5582                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5583                                                                 donesomething=1;
5584                                                         }
5585                                                         if(consolechars[0]>0){
5586                                                                 for(k=14;k>=1;k--){
5587                                                                         for(j=0;j<255;j++){
5588                                                                                 consoletext[k][j]=consoletext[k-1][j];
5589                                                                         }
5590                                                                         consolechars[k]=consolechars[k-1];
5591                                                                 }
5592                                                                 for(j=0;j<255;j++){
5593                                                                         consoletext[0][j]=' ';
5594                                                                 }
5595                                                                 consolechars[0]=0;
5596                                                                 consoleselected=0;
5597
5598                                                                 if(!donesomething){
5599                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
5600                                                                         FSOUND_SetVolume(channels[consolefailsound], 256);
5601                                                                         FSOUND_SetPaused(channels[consolefailsound], FALSE);
5602                                                                 }
5603                                                         }
5604                                                 }
5605                                         }
5606                                         togglekey[i]=1;
5607                                 }
5608                                 else {
5609                                         togglekey[i]=0;
5610                                         togglekeydelay[i]=0;
5611                                 }
5612                         }
5613
5614                         consoleblinkdelay-=multiplier;
5615                         if(consoleblinkdelay<=0){
5616                                 consoleblinkdelay=.3;
5617                                 consoleblink=1-consoleblink;
5618                         }
5619                 }
5620
5621                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5622                         tryquit=1;
5623                         if(mainmenu==3){
5624                                 if(newdetail>2)newdetail=detail;
5625                                 if(newdetail<0)newdetail=detail;
5626                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
5627                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5628                                 if(newscreenheight>3000)newscreenheight=screenheight;
5629                                 if(newscreenheight<0)newscreenheight=screenheight;
5630
5631                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5632                                 opstream << "Screenwidth:\n";
5633                                 opstream << newscreenwidth;
5634                                 opstream << "\nScreenheight:\n";
5635                                 opstream << newscreenheight;
5636                                 opstream << "\nMouse sensitivity:\n";
5637                                 opstream << usermousesensitivity;
5638                                 opstream << "\nBlur(0,1):\n";
5639                                 opstream << ismotionblur;
5640                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5641                                 opstream << newdetail;
5642                                 opstream << "\nFloating jump:\n";
5643                                 opstream << floatjump;
5644                                 opstream << "\nMouse jump:\n";
5645                                 opstream << mousejump;
5646                                 opstream << "\nAmbient sound:\n";
5647                                 opstream << ambientsound;
5648                                 opstream << "\nBlood (0,1,2):\n";
5649                                 opstream << bloodtoggle;
5650                                 opstream << "\nAuto slomo:\n";
5651                                 opstream << autoslomo;
5652                                 opstream << "\nFoliage:\n";
5653                                 opstream << foliage;
5654                                 opstream << "\nMusic:\n";
5655                                 opstream << musictoggle;
5656                                 opstream << "\nTrilinear:\n";
5657                                 opstream << trilinear;
5658                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5659                                 opstream << decals;
5660                                 opstream << "\nInvert mouse:\n";
5661                                 opstream << invertmouse;
5662                                 opstream << "\nGamespeed:\n";
5663                                 if(oldgamespeed==0)oldgamespeed=1;
5664                                 opstream << oldgamespeed;
5665                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5666                                 opstream << difficulty;
5667                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5668                                 opstream << damageeffects;
5669                                 opstream << "\nText:\n";
5670                                 opstream << texttoggle;
5671                                 opstream << "\nDebug:\n";
5672                                 opstream << debugmode;
5673                                 opstream << "\nVBL Sync:\n";
5674                                 opstream << vblsync;
5675                                 opstream << "\nShow Points:\n";
5676                                 opstream << showpoints;
5677                                 opstream << "\nAlways Blur:\n";
5678                                 opstream << alwaysblur;
5679                                 opstream << "\nImmediate mode (turn on on G5):\n";
5680                                 opstream << immediate;
5681                                 opstream << "\nVelocity blur:\n";
5682                                 opstream << velocityblur;
5683                             opstream << "\nVolume:\n";
5684                         opstream << volume;
5685                                 opstream << "\nForward key:\n";
5686                                 opstream << KeyToChar(forwardkey);
5687                                 opstream << "\nBack key:\n";
5688                                 opstream << KeyToChar(backkey);
5689                                 opstream << "\nLeft key:\n";
5690                                 opstream << KeyToChar(leftkey);
5691                                 opstream << "\nRight key:\n";
5692                                 opstream << KeyToChar(rightkey);
5693                                 opstream << "\nJump key:\n";
5694                                 opstream << KeyToChar(jumpkey);
5695                                 opstream << "\nCrouch key:\n";
5696                                 opstream << KeyToChar(crouchkey);
5697                                 opstream << "\nDraw key:\n";
5698                                 opstream << KeyToChar(drawkey);
5699                                 opstream << "\nThrow key:\n";
5700                                 opstream << KeyToChar(throwkey);
5701                                 opstream << "\nAttack key:\n";
5702                                 opstream << KeyToChar(attackkey);
5703                                 opstream << "\nChat key:\n";
5704                                 opstream << KeyToChar(chatkey);
5705                                 opstream.close();
5706                         }
5707                 }
5708
5709                 static int oldwinfreeze;
5710                 if(winfreeze&&!oldwinfreeze){
5711                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
5712                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
5713                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
5714                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
5715                 }
5716                 if(winfreeze==0)oldwinfreeze=winfreeze;
5717                 else oldwinfreeze++;
5718
5719                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5720                         if(winfreeze)winfreeze=0;
5721                         oldjumpkeydown=1;
5722                 }
5723                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5724                         if(winfreeze){
5725                                 mainmenu=9;
5726                                 gameon=0;
5727                         }
5728                 }
5729                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5730                         oldjumpkeydown=1;
5731                 }
5732                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5733
5734                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5735
5736                         static bool oldbuttondialogue;
5737
5738                         if(indialogue!=-1)talkdelay=1;
5739                         talkdelay-=multiplier;
5740
5741                         if(talkdelay<=0)
5742                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5743                                         for(i=0;i<numdialogues;i++){
5744                                                 int realdialoguetype;
5745                                                 bool special;
5746                                                 if(dialoguetype[i]>49){
5747                                                         realdialoguetype=dialoguetype[i]-50; 
5748                                                         special=1;
5749                                                 }
5750                                                 else if(dialoguetype[i]>39){
5751                                                         realdialoguetype=dialoguetype[i]-40; 
5752                                                         special=1;
5753                                                 }
5754                                                 else if(dialoguetype[i]>29){
5755                                                         realdialoguetype=dialoguetype[i]-30; 
5756                                                         special=1;
5757                                                 }
5758                                                 else if(dialoguetype[i]>19){
5759                                                         realdialoguetype=dialoguetype[i]-20; 
5760                                                         special=1;
5761                                                 }
5762                                                 else if(dialoguetype[i]>9){
5763                                                         realdialoguetype=dialoguetype[i]-10; 
5764                                                         special=1;
5765                                                 }
5766                                                 else {
5767                                                         realdialoguetype=dialoguetype[i];
5768                                                         special=0;
5769                                                 }
5770                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5771                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5772                                                                 whichdialogue=i;
5773                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5774                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5775                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5776                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5777                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5778                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5779                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5780                                                                 }
5781                                                                 directing=0;
5782                                                                 indialogue=0;
5783                                                                 dialoguetime=0;
5784                                                                 dialoguegonethrough[i]++;
5785                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5786                                                                         static float gLoc[3];
5787                                                                         static float vel[3];
5788                                                                         XYZ temppos;
5789                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5790                                                                         temppos=temppos-viewer;
5791                                                                         Normalise(&temppos);
5792                                                                         temppos+=viewer;
5793
5794                                                                         gLoc[0]=temppos.x;
5795                                                                         gLoc[1]=temppos.y;
5796                                                                         gLoc[2]=temppos.z;vel[0]=0;
5797                                                                         vel[1]=0;
5798                                                                         vel[2]=0;
5799                                                                         int whichsoundplay;
5800                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5801                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5802                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5803                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5804                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5805                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5806                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5807                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5808                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5809                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5810                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5811                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5812                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5813                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5814                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5815                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5816                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5817                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5818                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5819                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5820                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
5821                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5822                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
5823                                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
5824                                                                 }
5825                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5826                                                         }
5827                                                 }
5828                                         }
5829
5830                                         windvar+=multiplier;
5831                                         smoketex+=multiplier;
5832                                         tutorialstagetime+=multiplier;
5833
5834                                         static float hotspotvisual[40];
5835                                         if(numhotspots){
5836                                                 XYZ hotspotsprite;
5837                                                 if(editorenabled)
5838                                                         for(i=0;i<numhotspots;i++)
5839                                                                 hotspotvisual[i]-=multiplier/320;
5840
5841                                                 for(i=0;i<numhotspots;i++){
5842                                                         //if(hotspottype[i]<=10)
5843                                                         while(hotspotvisual[i]<0){
5844                                                                 hotspotsprite=0;
5845                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5846                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5847                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5848                                                                 hotspotsprite+=hotspot[i];
5849                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5850                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5851                                                         }                               
5852                                                 }
5853
5854                                                 for(i=0;i<numhotspots;i++){
5855                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5856                                                                 hotspot[i]=player[hotspottype[i]].coords;
5857                                                         }
5858                                                 }
5859                                         }
5860
5861                                         //Tutorial
5862                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5863                                                 tutorialstage++;
5864                                                 tutorialsuccess=0;
5865                                                 if(tutorialstage<=1){
5866                                                         canattack=0;
5867                                                         cananger=0;
5868                                                         reversaltrain=0;
5869                                                 }
5870                                                 if(tutorialstage==1){
5871                                                         tutorialmaxtime=5;
5872                                                 }
5873                                                 if(tutorialstage==2){
5874                                                         tutorialmaxtime=2;
5875                                                 }
5876                                                 if(tutorialstage==3){
5877                                                         tutorialmaxtime=600;
5878                                                 }
5879                                                 if(tutorialstage==4){
5880                                                         tutorialmaxtime=1000;
5881                                                 }
5882                                                 if(tutorialstage==5){
5883                                                         tutorialmaxtime=600;
5884                                                 }
5885                                                 if(tutorialstage==6){
5886                                                         tutorialmaxtime=600;
5887                                                 }
5888                                                 if(tutorialstage==7){
5889                                                         tutorialmaxtime=600;
5890                                                 }
5891                                                 if(tutorialstage==8){
5892                                                         tutorialmaxtime=600;
5893                                                 }
5894                                                 if(tutorialstage==9){
5895                                                         tutorialmaxtime=600;
5896                                                 }
5897                                                 if(tutorialstage==10){
5898                                                         tutorialmaxtime=2;
5899                                                 }
5900                                                 if(tutorialstage==11){
5901                                                         tutorialmaxtime=1000;
5902                                                 }
5903                                                 if(tutorialstage==12){
5904                                                         tutorialmaxtime=1000;
5905                                                 }
5906                                                 if(tutorialstage==13){
5907                                                         tutorialmaxtime=2;
5908                                                 }
5909                                                 if(tutorialstage==14){
5910                                                         tutorialmaxtime=3;
5911
5912                                                         XYZ temp,temp2;
5913
5914                                                         temp.x=1011;
5915                                                         temp.y=84;
5916                                                         temp.z=491;
5917                                                         temp2.x=1025;
5918                                                         temp2.y=75;
5919                                                         temp2.z=447;
5920
5921                                                         player[1].coords=(temp+temp2)/2;
5922
5923                                                         float gLoc[3];
5924                                                         float vel[3];
5925                                                         gLoc[0]=player[1].coords.x;
5926                                                         gLoc[1]=player[1].coords.y;
5927                                                         gLoc[2]=player[1].coords.z;
5928                                                         vel[0]=0;
5929                                                         vel[1]=0;
5930                                                         vel[2]=0;
5931                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
5932                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5933                                                         FSOUND_SetVolume(channels[fireendsound], 256);
5934                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
5935
5936                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5937                                                                 if(Random()%2==0){
5938                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5939                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5940                                                                         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;
5941                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5942                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5943                                                                 }
5944                                                         }
5945
5946                                                 }
5947                                                 if(tutorialstage==15){
5948                                                         tutorialmaxtime=500;
5949                                                 }
5950                                                 if(tutorialstage==16){
5951                                                         tutorialmaxtime=500;
5952                                                 }
5953                                                 if(tutorialstage==17){
5954                                                         tutorialmaxtime=500;
5955                                                 }
5956                                                 if(tutorialstage==18){
5957                                                         tutorialmaxtime=500;
5958                                                 }
5959                                                 if(tutorialstage==19){
5960                                                         tutorialstage=20;
5961                                                         //tutorialmaxtime=500;
5962                                                 }
5963                                                 if(tutorialstage==20){
5964                                                         tutorialmaxtime=500;
5965                                                 }
5966                                                 if(tutorialstage==21){
5967                                                         tutorialmaxtime=500;
5968                                                         if(bonus==cannon){
5969                                                                 bonus=Slicebonus;
5970                                                                 againbonus=1;
5971                                                         }
5972                                                         else againbonus=0;
5973                                                 }
5974                                                 if(tutorialstage==22){
5975                                                         tutorialmaxtime=500;
5976                                                 }
5977                                                 if(tutorialstage==23){
5978                                                         tutorialmaxtime=500;
5979                                                 }
5980                                                 if(tutorialstage==24){
5981                                                         tutorialmaxtime=500;
5982                                                 }
5983                                                 if(tutorialstage==25){
5984                                                         tutorialmaxtime=500;
5985                                                 }
5986                                                 if(tutorialstage==26){
5987                                                         tutorialmaxtime=2;
5988                                                 }
5989                                                 if(tutorialstage==27){
5990                                                         tutorialmaxtime=4;
5991                                                         reversaltrain=1;
5992                                                         cananger=1;
5993                                                         player[1].aitype=attacktypecutoff;
5994                                                 }
5995                                                 if(tutorialstage==28){
5996                                                         tutorialmaxtime=400;
5997                                                 }
5998                                                 if(tutorialstage==29){
5999                                                         tutorialmaxtime=400;
6000                                                         player[0].escapednum=0;
6001                                                 }
6002                                                 if(tutorialstage==30){
6003                                                         tutorialmaxtime=4;
6004                                                         reversaltrain=0;
6005                                                         cananger=0;
6006                                                         player[1].aitype=passivetype;
6007                                                 }
6008                                                 if(tutorialstage==31){
6009                                                         tutorialmaxtime=13;
6010                                                 }
6011                                                 if(tutorialstage==32){
6012                                                         tutorialmaxtime=8;
6013                                                 }
6014                                                 if(tutorialstage==33){
6015                                                         tutorialmaxtime=400;
6016                                                         cananger=1;
6017                                                         canattack=1;
6018                                                         player[1].aitype=attacktypecutoff;
6019                                                 }
6020                                                 if(tutorialstage==34){
6021                                                         tutorialmaxtime=400;
6022                                                 }
6023                                                 if(tutorialstage==35){
6024                                                         tutorialmaxtime=400;
6025                                                 }
6026                                                 if(tutorialstage==36){
6027                                                         tutorialmaxtime=2;
6028                                                         reversaltrain=0;
6029                                                         cananger=0;
6030                                                         player[1].aitype=passivetype;
6031                                                 }
6032                                                 if(tutorialstage==37){
6033                                                         damagedealt=0;
6034                                                         damagetaken=0;
6035                                                         tutorialmaxtime=50;
6036                                                         cananger=1;
6037                                                         canattack=1;
6038                                                         player[1].aitype=attacktypecutoff;
6039                                                 }
6040                                                 if(tutorialstage==38){
6041                                                         tutorialmaxtime=4;
6042                                                         canattack=0;
6043                                                         cananger=0;
6044                                                         player[1].aitype=passivetype;
6045                                                 }
6046                                                 if(tutorialstage==39){
6047                                                         XYZ temp,temp2;
6048
6049                                                         temp.x=1011;
6050                                                         temp.y=84;
6051                                                         temp.z=491;
6052                                                         temp2.x=1025;
6053                                                         temp2.y=75;
6054                                                         temp2.z=447;
6055
6056
6057                                                         weapons.owner[weapons.numweapons]=-1;
6058                                                         weapons.type[weapons.numweapons]=knife;
6059                                                         weapons.damage[weapons.numweapons]=0;
6060                                                         weapons.mass[weapons.numweapons]=1;
6061                                                         weapons.tipmass[weapons.numweapons]=1.2;
6062                                                         weapons.length[weapons.numweapons]=.25;
6063                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6064                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6065
6066                                                         weapons.velocity[weapons.numweapons]=0.1;
6067                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6068                                                         weapons.missed[weapons.numweapons]=1;
6069                                                         weapons.hitsomething[weapons.numweapons]=0;
6070                                                         weapons.freetime[weapons.numweapons]=0;
6071                                                         weapons.firstfree[weapons.numweapons]=1;
6072                                                         weapons.physics[weapons.numweapons]=1;
6073
6074                                                         weapons.numweapons++;
6075                                                 }
6076                                                 if(tutorialstage==40){
6077                                                         tutorialmaxtime=300;
6078                                                 }
6079                                                 if(tutorialstage==41){
6080                                                         tutorialmaxtime=300;
6081                                                 }
6082                                                 if(tutorialstage==42){
6083                                                         tutorialmaxtime=8;
6084                                                 }
6085                                                 if(tutorialstage==43){
6086                                                         tutorialmaxtime=300;
6087                                                 }
6088                                                 if(tutorialstage==44){
6089                                                         weapons.owner[0]=1;
6090                                                         player[0].weaponactive=-1;
6091                                                         player[0].num_weapons=0;
6092                                                         player[1].weaponactive=0;
6093                                                         player[1].num_weapons=1;
6094                                                         player[1].weaponids[0]=0;
6095
6096                                                         cananger=1;
6097                                                         canattack=1;
6098                                                         player[1].aitype=attacktypecutoff;
6099
6100                                                         tutorialmaxtime=300;
6101                                                 }
6102                                                 if(tutorialstage==45){
6103                                                         weapons.owner[0]=1;
6104                                                         player[0].weaponactive=-1;
6105                                                         player[0].num_weapons=0;
6106                                                         player[1].weaponactive=0;
6107                                                         player[1].num_weapons=1;
6108                                                         player[1].weaponids[0]=0;
6109
6110                                                         tutorialmaxtime=300;
6111                                                 }
6112                                                 if(tutorialstage==46){
6113                                                         weapons.owner[0]=1;
6114                                                         player[0].weaponactive=-1;
6115                                                         player[0].num_weapons=0;
6116                                                         player[1].weaponactive=0;
6117                                                         player[1].num_weapons=1;
6118                                                         player[1].weaponids[0]=0;
6119
6120                                                         weapons.type[0]=sword;
6121
6122                                                         tutorialmaxtime=300;
6123                                                 }
6124
6125                                                 if(tutorialstage==47){
6126                                                         tutorialmaxtime=10;
6127
6128                                                         XYZ temp,temp2;
6129
6130                                                         temp.x=1011;
6131                                                         temp.y=84;
6132                                                         temp.z=491;
6133                                                         temp2.x=1025;
6134                                                         temp2.y=75;
6135                                                         temp2.z=447;
6136
6137                                                         weapons.owner[weapons.numweapons]=-1;
6138                                                         weapons.type[weapons.numweapons]=sword;
6139                                                         weapons.damage[weapons.numweapons]=0;
6140                                                         weapons.mass[weapons.numweapons]=1;
6141                                                         weapons.tipmass[weapons.numweapons]=1.2;
6142                                                         weapons.length[weapons.numweapons]=.25;
6143                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6144                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6145
6146                                                         weapons.velocity[weapons.numweapons]=0.1;
6147                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6148                                                         weapons.missed[weapons.numweapons]=1;
6149                                                         weapons.hitsomething[weapons.numweapons]=0;
6150                                                         weapons.freetime[weapons.numweapons]=0;
6151                                                         weapons.firstfree[weapons.numweapons]=1;
6152                                                         weapons.physics[weapons.numweapons]=1;
6153
6154                                                         weapons.owner[0]=1;
6155                                                         weapons.owner[1]=0;
6156                                                         player[0].weaponactive=0;
6157                                                         player[0].num_weapons=1;
6158                                                         player[0].weaponids[0]=1;       
6159                                                         player[1].weaponactive=0;
6160                                                         player[1].num_weapons=1;
6161                                                         player[1].weaponids[0]=0;       
6162
6163                                                         weapons.numweapons++;
6164                                                 }
6165                                                 if(tutorialstage==48){
6166                                                         canattack=0;
6167                                                         cananger=0;
6168                                                         player[1].aitype=passivetype;
6169
6170                                                         tutorialmaxtime=15;
6171
6172                                                         weapons.owner[0]=1;
6173                                                         weapons.owner[1]=0;
6174                                                         player[0].weaponactive=0;
6175                                                         player[0].num_weapons=1;
6176                                                         player[0].weaponids[0]=1;       
6177                                                         player[1].weaponactive=0;
6178                                                         player[1].num_weapons=1;
6179                                                         player[1].weaponids[0]=0;
6180
6181                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
6182                                                         else weapons.type[0]=staff;
6183
6184                                                         weapons.numweapons++;
6185                                                 }
6186                                                 if(tutorialstage==49){
6187                                                         canattack=0;
6188                                                         cananger=0;
6189                                                         player[1].aitype=passivetype;
6190
6191                                                         tutorialmaxtime=200;
6192
6193                                                         weapons.position[1]=1000;
6194                                                         weapons.tippoint[1]=1000;
6195
6196                                                         weapons.numweapons=1;
6197                                                         weapons.owner[0]=0;
6198                                                         player[1].weaponactive=-1;
6199                                                         player[1].num_weapons=0;
6200                                                         player[0].weaponactive=0;
6201                                                         player[0].num_weapons=1;
6202                                                         player[0].weaponids[0]=0;       
6203
6204                                                         weapons.type[0]=knife;
6205
6206                                                         weapons.numweapons++;
6207                                                 }
6208                                                 if(tutorialstage==50){
6209                                                         tutorialmaxtime=8;
6210
6211                                                         XYZ temp,temp2;
6212                                                         float gLoc[3];
6213                                                         float vel[3];
6214                                                         gLoc[0]=player[1].coords.x;
6215                                                         gLoc[1]=player[1].coords.y;
6216                                                         gLoc[2]=player[1].coords.z;
6217                                                         vel[0]=0;
6218                                                         vel[1]=0;
6219                                                         vel[2]=0;
6220                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
6221                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6222                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6223                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6224
6225                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6226                                                                 if(Random()%2==0){
6227                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6228                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6229                                                                         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;
6230                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6231                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6232                                                                 }
6233                                                         }
6234
6235                                                         player[1].num_weapons=0;
6236                                                         player[1].weaponstuck=-1;
6237                                                         player[1].weaponactive=-1;
6238
6239                                                         weapons.numweapons=0;
6240
6241                                                         weapons.owner[0]=-1;
6242                                                         weapons.velocity[0]=0.1;
6243                                                         weapons.tipvelocity[0]=-0.1;
6244                                                         weapons.missed[0]=1;
6245                                                         weapons.hitsomething[0]=0;
6246                                                         weapons.freetime[0]=0;
6247                                                         weapons.firstfree[0]=1;
6248                                                         weapons.physics[0]=1;
6249                                                 }
6250                                                 if(tutorialstage==51){
6251                                                         tutorialmaxtime=80000;
6252                                                 }
6253                                                 if(tutorialstage<=51)tutorialstagetime=0;
6254                                         }
6255
6256                                         //Tutorial success
6257                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6258                                                 if(tutorialstage==3){
6259                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6260                                                 }
6261                                                 if(tutorialstage==4){
6262                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6263                                                 }
6264                                                 if(tutorialstage==5){
6265                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6266                                                 }
6267                                                 if(tutorialstage==6){
6268                                                         if(player[0].isCrouch())tutorialsuccess=1;
6269                                                 }
6270                                                 if(tutorialstage==7){
6271                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6272                                                 }
6273                                                 if(tutorialstage==8){
6274                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6275                                                 }
6276                                                 if(tutorialstage==9){
6277                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6278                                                 }
6279                                                 if(tutorialstage==11){
6280                                                         if(player[0].isWallJump())tutorialsuccess=1;
6281                                                 }
6282                                                 if(tutorialstage==12){
6283                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6284                                                 }
6285                                                 if(tutorialstage==15){
6286                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6287                                                 }
6288                                                 if(tutorialstage==16){
6289                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6290                                                 }
6291                                                 if(tutorialstage==17){
6292                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6293                                                 }
6294                                                 if(tutorialstage==18){
6295                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6296                                                 }
6297                                                 if(tutorialstage==19){
6298                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6299                                                 }
6300                                                 if(tutorialstage==20){
6301                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6302                                                 }
6303                                                 if(tutorialstage==21){
6304                                                         if(bonus==cannon)tutorialsuccess=1;
6305                                                 }
6306                                                 if(tutorialstage==22){
6307                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6308                                                 }
6309                                                 if(tutorialstage==23){
6310                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6311                                                 }
6312                                                 if(tutorialstage==24){
6313                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6314                                                 }
6315                                                 if(tutorialstage==25){
6316                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6317                                                 }
6318                                                 if(tutorialstage==28){
6319                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6320                                                 }
6321                                                 if(tutorialstage==29){
6322                                                         if(player[0].escapednum==2){
6323                                                                 tutorialsuccess=1;
6324                                                                 reversaltrain=0;
6325                                                                 cananger=0;
6326                                                                 player[1].aitype=passivetype;
6327                                                         }
6328                                                 }
6329                                                 if(tutorialstage==33){
6330                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6331                                                 }
6332                                                 if(tutorialstage==34){
6333                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6334                                                 }
6335                                                 if(tutorialstage==35){
6336                                                         if(animation[player[0].targetanimation].attack==reversal){
6337                                                                 tutorialsuccess=1;
6338                                                                 reversaltrain=0;
6339                                                                 cananger=0;
6340                                                                 player[1].aitype=passivetype;
6341                                                         }
6342                                                 }
6343                                                 if(tutorialstage==40){
6344                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6345                                                 }
6346                                                 if(tutorialstage==41){
6347                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6348                                                 }
6349                                                 if(tutorialstage==43){
6350                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6351                                                 }
6352                                                 if(tutorialstage==44){
6353                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6354                                                 }
6355                                                 if(tutorialstage==45){
6356                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6357                                                 }
6358                                                 if(tutorialstage==46){
6359                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6360                                                 }
6361                                                 if(tutorialstage==49){
6362                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6363                                                 }
6364                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6365
6366
6367                                                 if(tutorialstagetime==tutorialmaxtime-3){
6368                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
6369                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6370                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
6371                                                 }
6372
6373                                                 if(tutorialsuccess>=1){
6374                                                         if(tutorialstage==34||tutorialstage==35)
6375                                                                 tutorialstagetime=tutorialmaxtime-1;
6376                                                 }
6377                                         }
6378
6379                                         if(tutoriallevel){
6380                                                 if(tutorialstage<14||tutorialstage>=50){
6381                                                         player[1].coords.y=300;
6382                                                         player[1].velocity=0;
6383                                                 }
6384                                         }
6385
6386                                         if(tutoriallevel!=1){
6387                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6388                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
6389                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6390                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
6391                                                 }
6392                                         }
6393                                         else
6394                                                 if(bonustime==0){
6395                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
6396                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6397                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6398                                                 }
6399                                                 if(bonustime==0){
6400                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6401                                                         else bonusnum[bonus]+=0.15;
6402                                                         if(tutoriallevel)bonusvalue=0;
6403                                                         bonusvalue/=bonusnum[bonus];
6404                                                         bonustotal+=bonusvalue;
6405                                                 }
6406                                                 bonustime+=multiplier;
6407
6408                                                 if(environment==snowyenvironment){
6409                                                         precipdelay-=multiplier;
6410                                                         while(precipdelay<0){
6411                                                                 precipdelay+=.04;
6412                                                                 if(!detail)precipdelay+=.04;
6413                                                                 XYZ footvel,footpoint;
6414
6415                                                                 footvel=0;
6416                                                                 footpoint=viewer+viewerfacing*6;
6417                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6418                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6419                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6420                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6421                                                         }
6422                                                 }
6423                                                 for(k=0;k<numplayers;k++){
6424                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6425                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6426
6427                                                         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){
6428                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6429                                                                 else if(player[k].rotation>player[k].targetrotation){
6430                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6431                                                                 }
6432                                                                 else if(player[k].rotation<player[k].targetrotation){
6433                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6434                                                                 }
6435                                                         }
6436
6437
6438                                                         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))){
6439                                                                 player[k].turnspeed*=2;
6440                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6441                                                                 else if(player[k].rotation>player[k].targetrotation){
6442                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6443                                                                 }
6444                                                                 else if(player[k].rotation<player[k].targetrotation){
6445                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6446                                                                 }
6447                                                                 player[k].turnspeed/=2;
6448                                                         }
6449
6450                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6451                                                                 player[k].turnspeed*=4;
6452                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6453                                                                 else if(player[k].rotation>player[k].targetrotation){
6454                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6455                                                                 }
6456                                                                 else if(player[k].rotation<player[k].targetrotation){
6457                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6458                                                                 }
6459                                                                 player[k].turnspeed/=4;
6460                                                         }
6461
6462                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6463                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6464
6465                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6466                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6467                                                                         bool tempcollide=0;
6468
6469                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6470                                                                         if(player[k].collide>1)player[k].collide=1;
6471                                                                         player[k].collide-=multiplier*30;
6472
6473                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6474                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6475                                                                         }
6476                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6477                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6478                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6479                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6480                                                                                                 lowpoint=player[k].coords;
6481                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6482                                                                                                 else lowpoint.y+=1.3;
6483                                                                                                 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){
6484                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6485                                                                                                 }
6486                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6487                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6488                                                                                                 */
6489                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6490                                                                                                         flatfacing=lowpoint-player[k].coords;
6491                                                                                                         player[k].coords=lowpoint;
6492                                                                                                         player[k].coords.y-=1.3;
6493                                                                                                         player[k].collide=1;
6494                                                                                                         tempcollide=1;
6495                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6496                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6497                                                                                                                 tempcoords1=lowpoint;
6498                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6499                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6500                                                                                                                         player[k].target=0;
6501                                                                                                                         player[k].targetanimation=walljumpleftanim;
6502                                                                                                                         player[k].targetframe=0;
6503                                                                                                                         float gLoc[3];
6504                                                                                                                         float vel[3];
6505                                                                                                                         gLoc[0]=player[k].coords.x;
6506                                                                                                                         gLoc[1]=player[k].coords.y;
6507                                                                                                                         gLoc[2]=player[k].coords.z;
6508                                                                                                                         vel[0]=0;
6509                                                                                                                         vel[1]=0;
6510                                                                                                                         vel[2]=0;
6511                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6512                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6513                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6514                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6515                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6516
6517                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6518                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6519                                                                                                                         player[k].rotation*=360/6.28;
6520                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6521                                                                                                                         player[k].targetrotation=player[k].rotation;
6522                                                                                                                         player[k].lowrotation=player[k].rotation;
6523                                                                                                                         if(k==0)numwallflipped++;
6524                                                                                                                 }
6525                                                                                                                 else
6526                                                                                                                 {
6527                                                                                                                         lowpoint=tempcoords1;
6528                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6529                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6530                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6531                                                                                                                                 player[k].target=0;
6532                                                                                                                                 player[k].targetanimation=walljumprightanim;
6533                                                                                                                                 player[k].targetframe=0;
6534                                                                                                                                 float gLoc[3];
6535                                                                                                                                 float vel[3];
6536                                                                                                                                 gLoc[0]=player[k].coords.x;
6537                                                                                                                                 gLoc[1]=player[k].coords.y;
6538                                                                                                                                 gLoc[2]=player[k].coords.z;
6539                                                                                                                                 vel[0]=0;
6540                                                                                                                                 vel[1]=0;
6541                                                                                                                                 vel[2]=0;
6542                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6543                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6544                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6545                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6546                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6547
6548                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6549                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6550                                                                                                                                 player[k].rotation*=360/6.28;
6551                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6552                                                                                                                                 player[k].targetrotation=player[k].rotation;
6553                                                                                                                                 player[k].lowrotation=player[k].rotation;
6554                                                                                                                                 if(k==0)numwallflipped++;
6555                                                                                                                         }
6556                                                                                                                         else
6557                                                                                                                         {
6558                                                                                                                                 lowpoint=tempcoords1;
6559                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6560                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6561                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6562                                                                                                                                         player[k].target=0;
6563                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6564                                                                                                                                         player[k].targetframe=0;
6565                                                                                                                                         float gLoc[3];
6566                                                                                                                                         float vel[3];
6567                                                                                                                                         gLoc[0]=player[k].coords.x;
6568                                                                                                                                         gLoc[1]=player[k].coords.y;
6569                                                                                                                                         gLoc[2]=player[k].coords.z;
6570                                                                                                                                         vel[0]=0;
6571                                                                                                                                         vel[1]=0;
6572                                                                                                                                         vel[2]=0;
6573                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6574                                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6575                                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6576                                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6577                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6578
6579                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6580                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6581                                                                                                                                         player[k].rotation*=360/6.28;
6582                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6583                                                                                                                                         player[k].targetrotation=player[k].rotation;
6584                                                                                                                                         player[k].lowrotation=player[k].rotation;
6585                                                                                                                                         if(k==0)numwallflipped++;
6586                                                                                                                                 }
6587                                                                                                                                 else
6588                                                                                                                                 {
6589                                                                                                                                         lowpoint=tempcoords1;
6590                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6591                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6592                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6593                                                                                                                                                 player[k].target=0;
6594                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6595                                                                                                                                                 player[k].targetframe=0;
6596                                                                                                                                                 float gLoc[3];
6597                                                                                                                                                 float vel[3];
6598                                                                                                                                                 gLoc[0]=player[k].coords.x;
6599                                                                                                                                                 gLoc[1]=player[k].coords.y;
6600                                                                                                                                                 gLoc[2]=player[k].coords.z;
6601                                                                                                                                                 vel[0]=0;
6602                                                                                                                                                 vel[1]=0;
6603                                                                                                                                                 vel[2]=0;
6604                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6605                                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6606                                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6607                                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6608                                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6609
6610                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6611                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6612                                                                                                                                                 player[k].rotation*=360/6.28;
6613                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6614                                                                                                                                                 player[k].rotation+=180;
6615                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6616                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6617                                                                                                                                                 if(k==0)numwallflipped++;
6618                                                                                                                                         }
6619                                                                                                                                 }
6620                                                                                                                         }
6621                                                                                                                 }
6622                                                                                                         }
6623                                                                                                 }
6624                                                                                         }
6625                                                                                         else if(objects.type[i]==rocktype){
6626                                                                                                 lowpoint2=player[k].coords;
6627                                                                                                 lowpoint=player[k].coords;
6628                                                                                                 lowpoint.y+=2;
6629                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6630                                                                                                         player[k].coords=colpoint;
6631                                                                                                         player[k].collide=1;
6632                                                                                                         tempcollide=1;
6633
6634                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6635                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6636
6637                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6638                                                                                                                 player[k].target=0;
6639                                                                                                                 player[k].targetframe=0;        
6640                                                                                                                 player[k].onterrain=1;
6641
6642                                                                                                                 if(player[k].id==0){
6643                                                                                                                         FSOUND_SetPaused(channels[whooshsound], TRUE);
6644                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 0);
6645                                                                                                                 }
6646
6647                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6648                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6649                                                                                                                         player[k].targetanimation=player[k].getLanding();
6650                                                                                                                         float gLoc[3];
6651                                                                                                                         float vel[3];
6652                                                                                                                         gLoc[0]=player[k].coords.x;
6653                                                                                                                         gLoc[1]=player[k].coords.y;
6654                                                                                                                         gLoc[2]=player[k].coords.z;
6655                                                                                                                         vel[0]=player[k].velocity.x;
6656                                                                                                                         vel[1]=player[k].velocity.y;
6657                                                                                                                         vel[2]=player[k].velocity.z;
6658                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, TRUE);
6659                                                                                                                         FSOUND_3D_SetAttributes(channels[landsound], gLoc, vel);
6660                                                                                                                         FSOUND_SetVolume(channels[landsound], 128);
6661                                                                                                                         FSOUND_SetPaused(channels[landsound], FALSE);
6662                                                                                                                         if(k==0){
6663                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6664                                                                                                                                 envsoundvol[numenvsounds]=16;
6665                                                                                                                                 envsoundlife[numenvsounds]=.4;
6666                                                                                                                                 numenvsounds++;
6667                                                                                                                         }
6668
6669                                                                                                                 }
6670                                                                                                         }
6671                                                                                                 }                               
6672                                                                                         }
6673                                                                                 }
6674                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6675                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6676                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6677                                                                                                 lowpoint=player[k].coords;
6678                                                                                                 lowpoint.y+=1.35;
6679                                                                                                 if(objects.type[i]!=rocktype)
6680                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6681                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;               
6682                                                                                                                 player[k].coords=lowpoint;
6683                                                                                                                 player[k].coords.y-=1.35;
6684                                                                                                                 player[k].collide=1;    
6685
6686                                                                                                                 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)){
6687                                                                                                                         lowpoint=player[k].coords;
6688                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6689                                                                                                                         lowpoint=player[k].coords;
6690                                                                                                                         lowpoint.y+=.05;
6691                                                                                                                         facing=0;
6692                                                                                                                         facing.z=-1;
6693                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6694                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6695                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6696                                                                                                                         if(whichhit!=-1){
6697                                                                                                                                 lowpoint=player[k].coords;
6698                                                                                                                                 lowpoint.y+=.1;
6699                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6700                                                                                                                                 lowpoint2=lowpoint;
6701                                                                                                                                 lowpointtarget2=lowpointtarget;
6702                                                                                                                                 lowpoint3=lowpoint;
6703                                                                                                                                 lowpointtarget3=lowpointtarget;
6704                                                                                                                                 lowpoint4=lowpoint;
6705                                                                                                                                 lowpointtarget4=lowpointtarget;
6706                                                                                                                                 lowpoint5=lowpoint;
6707                                                                                                                                 lowpointtarget5=lowpointtarget;
6708                                                                                                                                 lowpoint6=lowpoint;
6709                                                                                                                                 lowpointtarget6=lowpointtarget;
6710                                                                                                                                 lowpoint7=lowpoint;
6711                                                                                                                                 lowpointtarget7=lowpoint;
6712                                                                                                                                 lowpoint2.x+=.1;
6713                                                                                                                                 lowpointtarget2.x+=.1;
6714                                                                                                                                 lowpoint3.z+=.1;
6715                                                                                                                                 lowpointtarget3.z+=.1;
6716                                                                                                                                 lowpoint4.x-=.1;
6717                                                                                                                                 lowpointtarget4.x-=.1;
6718                                                                                                                                 lowpoint5.z-=.1;
6719                                                                                                                                 lowpointtarget5.z-=.1;
6720                                                                                                                                 lowpoint6.y+=45/13;
6721                                                                                                                                 lowpointtarget6.y+=45/13;
6722                                                                                                                                 lowpointtarget6+=facing*.6;
6723                                                                                                                                 lowpointtarget7.y+=90/13;
6724                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6725                                                                                                                                 if(objects.friction[i]>.5)
6726                                                                                                                                         if(whichhit!=-1){
6727                                                                                                                                                 //if(k==0){
6728                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6729                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6730                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6731                                                                                                                                                                 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)
6732                                                                                                                                                                         for(j=0;j<45;j++){
6733                                                                                                                                                                                 lowpoint=player[k].coords;
6734                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6735                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6736                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6737                                                                                                                                                                                         if(j<=6){
6738                                                                                                                                                                                                 j=100;
6739                                                                                                                                                                                         }
6740                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6741                                                                                                                                                                                         j=100;
6742                                                                                                                                                                                         }*/
6743                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6744                                                                                                                                                                                                 j=100;
6745                                                                                                                                                                                         }
6746                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6747                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6748                                                                                                                                                                                                 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)*/){
6749                                                                                                                                                                                                         lowpoint=player[k].coords;
6750                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6751                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6752                                                                                                                                                                                                         flatfacing=player[k].coords;
6753                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6754                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6755                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6756
6757                                                                                                                                                                                                         if(j>10||!player[k].isRun()){                                                                                                   
6758                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6759                                                                                                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6760                                                                                                                                                                                                                 }
6761                                                                                                                                                                                                                 float gLoc[3];
6762                                                                                                                                                                                                                 float vel[3];
6763                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6764                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6765                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6766                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6767                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6768                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6769                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
6770                                                                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6771                                                                                                                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
6772                                                                                                                                                                                                                 FSOUND_SetPaused(channels[jumpsound], FALSE);
6773
6774                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6775                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6776                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6777                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6778                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6779                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6780
6781                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6782                                                                                                                                                                                                                 player[k].velocity=0;
6783
6784                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6785                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6786                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6787                                                                                                                                                                                                                         player[k].jumppower=0;
6788                                                                                                                                                                                                                         player[k].jumpclimb=1;
6789                                                                                                                                                                                                                 }
6790                                                                                                                                                                                                                 player[k].transspeed=6;
6791                                                                                                                                                                                                                 player[k].target=0;
6792
6793                                                                                                                                                                                                                 //player[k].currentframe=1;
6794                                                                                                                                                                                                                 player[k].targetframe=1;
6795                                                                                                                                                                                                                 if(j>25){
6796                                                                                                                                                                                                                         //player[k].currentframe=0;
6797                                                                                                                                                                                                                         player[k].targetframe=0;
6798                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6799                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6800                                                                                                                                                                                                                         player[k].jumppower=0;
6801                                                                                                                                                                                                                 }       
6802                                                                                                                                                                                                         }
6803                                                                                                                                                                                                         j=100;
6804                                                                                                                                                                                                 }
6805                                                                                                                                                                                         }
6806                                                                                                                                                                                 }
6807                                                                                                                                                                         }
6808                                                                                                                                                                         //}
6809                                                                                                                                         }
6810                                                                                                                         }
6811                                                                                                                 }
6812                                                                                                         }
6813                                                                                         }
6814                                                                                         if(player[k].collide<=0){
6815                                                                                                 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()){
6816                                                                                                         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)){
6817                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6818                                                                                                                 player[k].targetanimation=jumpdownanim;
6819                                                                                                                 player[k].targetframe=0;
6820                                                                                                                 player[k].target=0;
6821
6822                                                                                                                 float gLoc[3];
6823                                                                                                                 float vel[3];
6824                                                                                                                 gLoc[0]=player[k].coords.x;
6825                                                                                                                 gLoc[1]=player[k].coords.y;
6826                                                                                                                 gLoc[2]=player[k].coords.z;
6827                                                                                                                 vel[0]=player[k].velocity.x;
6828                                                                                                                 vel[1]=player[k].velocity.y;
6829                                                                                                                 vel[2]=player[k].velocity.z;
6830                                                                                                                 if(k==0){
6831                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
6832                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6833                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
6834                                                                                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
6835                                                                                                                 }
6836                                                                                                         }
6837                                                                                                         player[k].velocity.y+=gravity;
6838                                                                                                 }
6839                                                                                         }
6840                                                                 }
6841                                                         }
6842                                                         player[k].realoldcoords=player[k].coords;
6843                                                 }
6844
6845                                                 static XYZ oldviewer;
6846
6847                                                 if(indialogue==-1){
6848                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6849                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6850                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6851                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6852                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6853                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6854                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6855                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6856                                                 }
6857                                                 else
6858                                                 {
6859                                                         player[0].forwardkeydown=0;
6860                                                         player[0].leftkeydown=0;
6861                                                         player[0].backkeydown=0;
6862                                                         player[0].rightkeydown=0;
6863                                                         player[0].jumpkeydown=0;
6864                                                         player[0].crouchkeydown=0;
6865                                                         player[0].drawkeydown=0;
6866                                                         player[0].throwkeydown=0;
6867                                                 }
6868
6869                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6870
6871
6872                                                 static bool endkeydown;
6873                                                 if(indialogue!=-1){
6874                                                         cameramode=1;
6875                                                         if(directing){  
6876                                                                 facing=0;
6877                                                                 facing.z=-1;
6878
6879                                                                 facing=DoRotation(facing,-rotation2,0,0);
6880                                                                 facing=DoRotation(facing,0,0-rotation,0);
6881
6882                                                                 flatfacing=0;
6883                                                                 flatfacing.z=-1;
6884
6885                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6886
6887                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6888                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6889                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6890                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6891                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6892                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6893                                                                 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)
6894                                                                         ||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)
6895                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6896                                                                                 int whichend;
6897                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6898                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6899                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6900                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6901                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6902                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6903                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6904                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6905                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6906                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6907                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6908                                                                                 if(whichend!=-1){
6909                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6910                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6911                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6912                                                                                 }
6913                                                                                 if(whichend==-1){
6914                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6915                                                                                 }
6916                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6917                                                                                         indialogue=-1;
6918                                                                                         directing=0;
6919                                                                                         cameramode=0;
6920                                                                                 }
6921                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6922                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6923                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6924                                                                                 indialogue++;
6925                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6926                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6927                                                                                                 static float gLoc[3];
6928                                                                                                 static float vel[3];
6929                                                                                                 XYZ temppos;
6930                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6931                                                                                                 temppos=temppos-viewer;
6932                                                                                                 Normalise(&temppos);
6933                                                                                                 temppos+=viewer;
6934
6935                                                                                                 gLoc[0]=temppos.x;
6936                                                                                                 gLoc[1]=temppos.y;
6937                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
6938                                                                                                 vel[1]=0;
6939                                                                                                 vel[2]=0;
6940                                                                                                 int whichsoundplay;
6941                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6942                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6943                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6944                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6945                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6946                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6947                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6948                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6949                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6950                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6951                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6952                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6953                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6954                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6955                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6956                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6957                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6958                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6959                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6960                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6961                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
6962                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6963                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
6964                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
6965                                                                                         }
6966                                                                                 }
6967
6968                                                                                 for(j=0;j<numplayers;j++){
6969                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6970                                                                                 }
6971
6972                                                                                 endkeydown=1;
6973                                                                         }
6974                                                                         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)
6975                                                                                 ||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)
6976                                                                                 )){
6977                                                                                         int whichend;
6978                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
6979                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
6980                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
6981                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
6982                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
6983                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
6984                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
6985                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
6986                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
6987                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
6988                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
6989                                                                                 }
6990                                                                                 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)
6991                                                                                         &&!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)
6992                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6993                                                                                                 endkeydown=0;
6994                                                                                         }
6995                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6996                                                                                                 indialogue=-1;
6997                                                                                                 directing=0;
6998                                                                                                 cameramode=0;
6999                                                                                         }
7000                                                         }
7001                                                         if(!directing){ 
7002                                                                 FSOUND_SetPaused(channels[whooshsound], TRUE);
7003                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
7004                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
7005                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
7006                                                                 }                               
7007                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
7008                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
7009                                                                 if(dialoguetime>0.5)
7010                                                                         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)
7011                                                                                 ||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)
7012                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
7013                                                                                         indialogue++;
7014                                                                                         endkeydown=1;
7015                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
7016                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
7017                                                                                                         static float gLoc[3];
7018                                                                                                         static float vel[3];
7019                                                                                                         XYZ temppos;
7020                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7021                                                                                                         temppos=temppos-viewer;
7022                                                                                                         Normalise(&temppos);
7023                                                                                                         temppos+=viewer;
7024
7025                                                                                                         gLoc[0]=temppos.x;
7026                                                                                                         gLoc[1]=temppos.y;
7027                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
7028                                                                                                         vel[1]=0;
7029                                                                                                         vel[2]=0;
7030                                                                                                         int whichsoundplay;
7031                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7032                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7033                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7034                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7035                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7036                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7037                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7038                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7039                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7040                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7041                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7042                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7043                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7044                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7045                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7046                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7047                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7048                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7049                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7050                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7051                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
7052                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
7053                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
7054                                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7055                                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
7056                                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
7057                                                                                                         }
7058                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
7059                                                                                                                 hotspot[numhotspots]=player[0].coords;
7060                                                                                                                 hotspotsize[numhotspots]=10;
7061                                                                                                                 hotspottype[numhotspots]=-1;
7062
7063                                                                                                                 numhotspots++;
7064                                                                                                         }
7065                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
7066                                                                                                                 hostile=1;
7067                                                                                                         }
7068
7069                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
7070                                                                                                                 indialogue=-1;
7071                                                                                                                 directing=0;
7072                                                                                                                 cameramode=0;
7073                                                                                                         }
7074                                                                                                 }
7075                                                                                         }
7076                                                                                 }
7077                                                                                 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)
7078                                                                                         &&!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)
7079                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7080                                                                                                 endkeydown=0;
7081                                                                                         }
7082                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7083                                                                                                 indialogue=-1;
7084                                                                                                 directing=0;
7085                                                                                                 cameramode=0;
7086                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
7087                                                                                                         hostile=1;
7088                                                                                                 }
7089                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
7090                                                                                                         windialogue=1;
7091                                                                                                 }
7092                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
7093                                                                                                         hostile=1;
7094                                                                                                         for(i=1;i<numplayers;i++){
7095                                                                                                                 player[i].aitype = attacktypecutoff;
7096                                                                                                         }
7097                                                                                                 }
7098                                                                                         }
7099                                                         }
7100                                                 }
7101
7102                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
7103                                                 else oldbuttondialogue=1;
7104
7105                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
7106
7107                                                 //Net updates
7108
7109                                                 /*keyrefreshdelay-=multiplier;
7110                                                 bigrefreshdelay-=multiplier;
7111
7112                                                 if(keyrefreshdelay<=0){
7113                                                 static int concat[4];
7114
7115                                                 concat[0]=player[0].forwardkeydown;
7116                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
7117                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
7118                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
7119                                                 concat[0]=concat[0]*2+player[0].backkeydown;
7120                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
7121                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
7122                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
7123
7124                                                 concat[1]=player[0].crouchtogglekeydown;
7125                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
7126                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
7127                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
7128                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
7129                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
7130
7131                                                 //concat[2]=(char)((int)(rotation/2)%180);
7132
7133                                                 //concat[3]=(char)((int)(rotation2/2)%180);
7134
7135                                                 chatname[0]=concat[0]-128;
7136                                                 chatname[1]=concat[1]-128;
7137                                                 //chatname[2]=concat[2]-128;
7138                                                 //chatname[3]=concat[3]-128;
7139                                                 int temppoint=2;
7140                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
7141                                                 temppoint+=sizeof(float);
7142                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
7143                                                 temppoint+=sizeof(float);
7144
7145                                                 chatname[temppoint]='\0';
7146
7147                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
7148                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
7149                                                 //keyrefreshdelay=.01;
7150                                                 keyrefreshdelay=.03;
7151                                                 }
7152
7153                                                 if(bigrefreshdelay<=0){
7154                                                 for(i=0;i<1;i++){
7155                                                 /*int temppoint=0;
7156                                                 memcpy(chatname+temppoint,&i,sizeof(int));
7157                                                 temppoint+=sizeof(int);
7158                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
7159                                                 temppoint+=sizeof(float);
7160                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
7161                                                 temppoint+=sizeof(float);
7162                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
7163                                                 temppoint+=sizeof(float);
7164                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
7165                                                 temppoint+=sizeof(float);
7166                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
7167                                                 temppoint+=sizeof(float);
7168                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
7169                                                 temppoint+=sizeof(int);
7170                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
7171                                                 temppoint+=sizeof(int);
7172                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
7173                                                 temppoint+=sizeof(float);
7174                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
7175                                                 temppoint+=sizeof(float);
7176                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
7177                                                 temppoint+=sizeof(float);
7178                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
7179                                                 temppoint+=sizeof(int);
7180                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
7181                                                 temppoint+=sizeof(int);
7182                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
7183                                                 temppoint+=sizeof(float);
7184                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
7185                                                 temppoint+=sizeof(float);
7186                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
7187                                                 temppoint+=sizeof(float);
7188                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
7189                                                 temppoint+=sizeof(int);
7190                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
7191                                                 temppoint+=sizeof(int);
7192                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
7193                                                 temppoint+=sizeof(int);
7194                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
7195                                                 temppoint+=sizeof(int);
7196                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
7197                                                 temppoint+=sizeof(int);
7198                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
7199                                                 temppoint+=sizeof(int);
7200                                                 chatname[temppoint]='\0';
7201
7202                                                 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);
7203                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
7204                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
7205
7206                                                 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);
7207
7208                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
7209                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
7210                                                 }
7211                                                 //bigrefreshdelay=.02;
7212                                                 bigrefreshdelay=.1;
7213                                                 }
7214                                                 }*/
7215
7216                                                 if(!player[0].jumpkeydown){
7217                                                         player[0].jumptogglekeydown=0;
7218                                                 }
7219                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
7220
7221
7222                                                 dialoguetime+=multiplier;
7223                                                 skybox.cloudmove+=multiplier;
7224                                                 hawkrotation+=multiplier*25;
7225                                                 realhawkcoords=0;
7226                                                 realhawkcoords.x=25;
7227                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
7228                                                 hawkcalldelay-=multiplier/2;
7229
7230                                                 if(hawkcalldelay<=0)
7231                                                 {
7232                                                         static float gLoc[3];
7233                                                         static float vel[3];
7234                                                         gLoc[0]=realhawkcoords.x;
7235                                                         gLoc[1]=realhawkcoords.y;
7236                                                         gLoc[2]=realhawkcoords.z;
7237                                                         vel[0]=0;
7238                                                         vel[1]=0;
7239                                                         vel[2]=0;
7240                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, TRUE);
7241                                                         FSOUND_3D_SetAttributes(channels[hawksound], gLoc, vel);
7242                                                         FSOUND_SetVolume(channels[hawksound], 128);
7243                                                         FSOUND_SetPaused(channels[hawksound], FALSE);
7244
7245                                                         hawkcalldelay=16+abs(Random()%8);
7246                                                 }
7247                                                 static float temptexdetail;
7248
7249
7250                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7251                                                         player[0].damagetolerance=200000;
7252                                                         player[0].damage=0;
7253                                                         player[0].burnt=0;
7254                                                         player[0].permanentdamage=0;
7255                                                         player[0].superpermanentdamage=0;
7256                                                         /*
7257                                                         int whichchar;
7258                                                         whichchar = abs(Random()%7);
7259                                                         registrationname[whichchar]+=1;
7260                                                         */
7261                                                 }
7262
7263                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7264                                                         environment++;
7265                                                         if(environment>2)environment=0;
7266                                                         Setenvironment(environment);
7267
7268                                                         envtogglekeydown=1;
7269                                                 }
7270
7271
7272                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7273                                                         envtogglekeydown=0;
7274                                                 }
7275
7276                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7277                                                         cameramode=1-cameramode;
7278                                                         cameratogglekeydown=1;
7279                                                 }
7280
7281                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7282                                                         cameratogglekeydown=0;
7283                                                 }
7284
7285                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7286                                                         if(player[0].num_weapons>0){
7287                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7288                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7289                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7290                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7291                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7292                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7293                                                                         weapons.length[player[0].weaponids[0]]=.8;
7294                                                                 }
7295                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7296                                                                         weapons.mass[player[0].weaponids[0]]=2;
7297                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7298                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7299                                                                 }
7300
7301                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7302                                                                         weapons.mass[player[0].weaponids[0]]=1;
7303                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7304                                                                         weapons.length[player[0].weaponids[0]]=.25;
7305                                                                 }
7306                                                         }
7307
7308                                                         /*for(i=0;i<objects.numobjects;i++){
7309                                                         if(objects.type[i]==treeleavestype){
7310                                                         for(j=0;j<objects.numobjects;j++){
7311                                                         if(objects.type[j]==treetrunktype)
7312                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7313                                                         objects.scale[i]=objects.scale[j];      
7314                                                         }
7315                                                         }
7316                                                         }*/
7317                                                         detailtogglekeydown=1;
7318                                                 }
7319
7320                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7321                                                         int closest=-1;
7322                                                         float closestdist=-1;
7323                                                         float distance;
7324                                                         if(numplayers>1)
7325                                                                 for(i=1;i<numplayers;i++){
7326                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7327                                                                         if(closestdist==-1||distance<closestdist){
7328                                                                                 closestdist=distance;
7329                                                                                 closest=i;
7330                                                                         }
7331                                                                 }
7332                                                                 if(closest!=-1){
7333                                                                         if(player[closest].num_weapons)
7334                                                                         {
7335                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7336                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7337                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7338                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7339                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7340                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7341                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7342                                                                                 }
7343                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7344                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7345                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7346                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7347                                                                                 }
7348                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7349                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7350                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7351                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7352                                                                                 }
7353                                                                         }
7354                                                                         if(!player[closest].num_weapons)
7355                                                                         {
7356                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7357                                                                                 weapons.owner[weapons.numweapons]=closest;
7358                                                                                 weapons.type[weapons.numweapons]=knife;
7359                                                                                 weapons.damage[weapons.numweapons]=0;
7360                                                                                 weapons.numweapons++;
7361                                                                                 player[closest].num_weapons=1;
7362                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7363                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7364                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7365                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7366                                                                                 }
7367                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7368                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7369                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7370                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7371                                                                                 }
7372                                                                         }
7373                                                                 }
7374                                                                 detailtogglekeydown=1;
7375                                                 }
7376
7377                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7378                                                         int closest=-1;
7379                                                         float closestdist=-1;
7380                                                         float distance;
7381                                                         if(numplayers>1)
7382                                                                 for(i=1;i<numplayers;i++){
7383                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7384                                                                         if(closestdist==-1||distance<closestdist){
7385                                                                                 closestdist=distance;
7386                                                                                 closest=i;
7387                                                                         }
7388                                                                 }
7389
7390                                                                 player[closest].rotation+=multiplier*50;
7391                                                                 player[closest].targetrotation=player[closest].rotation;
7392                                                 }
7393
7394
7395                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7396                                                         int closest=-1;
7397                                                         float closestdist=-1;
7398                                                         float distance;
7399                                                         if(numplayers>1)
7400                                                                 for(i=1;i<numplayers;i++){
7401                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7402                                                                         if(closestdist==-1||distance<closestdist){
7403                                                                                 closestdist=distance;
7404                                                                                 closest=i;
7405                                                                         }
7406                                                                 }
7407                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7408
7409                                                                 if(closest!=-1){
7410                                                                         player[closest].whichskin++;
7411                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7412                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7413
7414                                                                         if(player[closest].creature==rabbittype){
7415                                                                                 if(player[closest].whichskin==0){
7416                                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7417                                                                                 }
7418                                                                                 else if(player[closest].whichskin==1){
7419                                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7420                                                                                 }
7421                                                                                 else if(player[closest].whichskin==2){
7422                                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7423                                                                                 }
7424                                                                                 else if(player[closest].whichskin==3){
7425                                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7426                                                                                 }
7427                                                                                 else if(player[closest].whichskin==4){
7428                                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7429                                                                                 }
7430                                                                                 else if(player[closest].whichskin==5){
7431                                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7432                                                                                 }
7433                                                                                 else if(player[closest].whichskin==6){
7434                                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7435                                                                                 }
7436                                                                                 else if(player[closest].whichskin==7){
7437                                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7438                                                                                 }
7439                                                                                 else if(player[closest].whichskin==8){
7440                                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7441                                                                                 }
7442                                                                                 else if(player[closest].whichskin==9){
7443                                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7444                                                                                 }
7445                                                                         }
7446                                                                         if(player[closest].creature==wolftype){
7447                                                                                 k=abs(Random()%3);
7448                                                                                 if(player[closest].whichskin==0){
7449                                                                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7450                                                                                 }
7451                                                                                 else if(player[closest].whichskin==1){
7452                                                                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7453                                                                                 }
7454                                                                                 else if(player[closest].whichskin==2){
7455                                                                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7456                                                                                 }
7457                                                                         }
7458                                                                 }
7459
7460                                                                 if(player[closest].numclothes){
7461                                                                         for(i=0;i<player[closest].numclothes;i++){
7462                                                                                 tintr=player[closest].clothestintr[i];
7463                                                                                 tintg=player[closest].clothestintg[i];
7464                                                                                 tintb=player[closest].clothestintb[i];
7465                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7466                                                                         }
7467                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7468                                                                 }
7469
7470                                                                 detailtogglekeydown=1;
7471                                                 }
7472
7473                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7474                                                         int closest=-1;
7475                                                         float closestdist=-1;
7476                                                         float distance;
7477                                                         if(numplayers>1)
7478                                                                 for(i=1;i<numplayers;i++){
7479                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7480                                                                         if(closestdist==-1||distance<closestdist){
7481                                                                                 closestdist=distance;
7482                                                                                 closest=i;
7483                                                                         }
7484                                                                 }
7485                                                                 if(closest!=-1){
7486                                                                         if(player[closest].creature==wolftype){
7487                                                                                 headprop=player[closest].proportionhead.x/1.1;
7488                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7489                                                                                 armprop=player[closest].proportionarms.x/1.1;
7490                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7491                                                                         }
7492
7493                                                                         if(player[closest].creature==rabbittype){
7494                                                                                 headprop=player[closest].proportionhead.x/1.2;
7495                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7496                                                                                 armprop=player[closest].proportionarms.x/1.00;
7497                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7498                                                                         }
7499
7500
7501                                                                         if(player[closest].creature==rabbittype){
7502                                                                                 player[closest].skeleton.id=closest;
7503                                                                                 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);
7504                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7505                                                                                 player[closest].whichskin=0;
7506                                                                                 player[closest].creature=wolftype;
7507
7508                                                                                 player[closest].proportionhead=1.1;
7509                                                                                 player[closest].proportionbody=1.1;
7510                                                                                 player[closest].proportionarms=1.1;
7511                                                                                 player[closest].proportionlegs=1.1;
7512                                                                                 player[closest].proportionlegs.y=1.1;
7513                                                                                 player[closest].scale=.23*5*player[0].scale;
7514
7515                                                                                 player[closest].damagetolerance=300;
7516                                                                         }
7517                                                                         else
7518                                                                         {
7519                                                                                 player[closest].skeleton.id=closest;
7520                                                                                 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);
7521                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7522                                                                                 player[closest].whichskin=0;
7523                                                                                 player[closest].creature=rabbittype;
7524
7525                                                                                 player[closest].proportionhead=1.2;
7526                                                                                 player[closest].proportionbody=1.05;
7527                                                                                 player[closest].proportionarms=1.00;
7528                                                                                 player[closest].proportionlegs=1.1;
7529                                                                                 player[closest].proportionlegs.y=1.05;
7530                                                                                 player[closest].scale=.2*5*player[0].scale;
7531
7532                                                                                 player[closest].damagetolerance=200;
7533                                                                         }
7534
7535                                                                         if(player[closest].creature==wolftype){
7536                                                                                 player[closest].proportionhead=1.1*headprop;
7537                                                                                 player[closest].proportionbody=1.1*bodyprop;
7538                                                                                 player[closest].proportionarms=1.1*armprop;
7539                                                                                 player[closest].proportionlegs=1.1*legprop;
7540                                                                         }
7541
7542                                                                         if(player[closest].creature==rabbittype){
7543                                                                                 player[closest].proportionhead=1.2*headprop;
7544                                                                                 player[closest].proportionbody=1.05*bodyprop;
7545                                                                                 player[closest].proportionarms=1.00*armprop;
7546                                                                                 player[closest].proportionlegs=1.1*legprop;
7547                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7548                                                                         }
7549
7550                                                                 }
7551                                                                 detailtogglekeydown=1;
7552                                                 }
7553
7554                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7555                                                         detailtogglekeydown=0;
7556                                                 }
7557
7558                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7559                                                         slomo=1-slomo;
7560                                                         slomodelay=1000;
7561                                                         slomotogglekeydown=1;
7562                                                 }
7563
7564
7565                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7566                                                         int closest=-1;
7567                                                         float closestdist=-1;
7568                                                         float distance;
7569                                                         XYZ flatfacing2,flatvelocity2;
7570                                                         XYZ blah;
7571                                                         if(numplayers>1)
7572                                                                 for(i=1;i<numplayers;i++){
7573                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7574                                                                         if(distance<144&&!player[i].headless)
7575                                                                                 if(closestdist==-1||distance<closestdist){
7576                                                                                         closestdist=distance;
7577                                                                                         closest=i;
7578                                                                                         blah = player[i].coords;
7579                                                                                 }
7580                                                                 }
7581
7582                                                                 if(closest!=-1){                
7583                                                                         XYZ headspurtdirection;
7584                                                                         int i = player[closest].skeleton.jointlabels[head];
7585                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7586                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7587                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7588                                                                                 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;
7589                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7590                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7591                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7592                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7593                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7594                                                                                 Normalise(&headspurtdirection);
7595                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7596                                                                                 flatvelocity2+=headspurtdirection*8;
7597                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7598                                                                         }
7599                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7600
7601                                                                         float gLoc[3];
7602                                                                         float vel[3];
7603                                                                         gLoc[0]=blah.x;
7604                                                                         gLoc[1]=blah.y;
7605                                                                         gLoc[2]=blah.z;
7606                                                                         vel[0]=0;
7607                                                                         vel[1]=0;
7608                                                                         vel[2]=0;
7609                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
7610                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7611                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7612                                                                         FSOUND_SetPaused(channels[splattersound], FALSE);
7613
7614                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
7615                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7616                                                                         FSOUND_SetVolume(channels[breaksound2], 100);
7617                                                                         FSOUND_SetPaused(channels[breaksound2], FALSE);
7618
7619                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7620                                                                         player[closest].RagDoll(0);
7621                                                                         player[closest].dead=2;
7622                                                                         player[closest].headless=1;
7623                                                                         player[closest].DoBloodBig(3,165);
7624
7625                                                                         camerashake+=.3;
7626                                                                 }
7627
7628                                                                 explodetogglekeydown=1;
7629                                                 }
7630
7631                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7632                                                         int closest=-1;
7633                                                         float closestdist=-1;
7634                                                         float distance;
7635                                                         XYZ flatfacing2,flatvelocity2;
7636                                                         XYZ blah;
7637                                                         if(numplayers>1)
7638                                                                 for(i=1;i<numplayers;i++){
7639                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7640                                                                         if(distance<144)
7641                                                                                 if(closestdist==-1||distance<closestdist){
7642                                                                                         closestdist=distance;
7643                                                                                         closest=i;
7644                                                                                         blah=player[i].coords;
7645                                                                                 }
7646                                                                 }
7647
7648                                                                 if(closest!=-1){                
7649                                                                         float gLoc[3];
7650                                                                         float vel[3];
7651                                                                         gLoc[0]=blah.x;
7652                                                                         gLoc[1]=blah.y;
7653                                                                         gLoc[2]=blah.z;
7654                                                                         vel[0]=0;
7655                                                                         vel[1]=0;
7656                                                                         vel[2]=0;
7657
7658                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
7659                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7660                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7661                                                                         FSOUND_SetPaused(channels[splattersound], FALSE);
7662
7663                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
7664                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7665                                                                         FSOUND_SetVolume(channels[breaksound2], 600);
7666                                                                         FSOUND_SetPaused(channels[breaksound2], FALSE);
7667
7668                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7669                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7670                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7671                                                                                 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;
7672                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7673                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7674                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7675                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7676                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7677                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7678                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7679                                                                         }
7680
7681                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7682                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7683                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7684                                                                                 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;
7685                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7686                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7687                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7688                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7689                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7690                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7691                                                                         }
7692
7693                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7694                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7695                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7696                                                                                 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;
7697                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7698                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7699                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7700                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7701                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7702                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7703                                                                         }
7704
7705                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7706                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7707                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7708                                                                                 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;
7709                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7710                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7711                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7712                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7713                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7714                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7715                                                                         }
7716
7717                                                                         XYZ temppos;
7718                                                                         for(j=0;j<numplayers; j++){
7719                                                                                 if(j!=closest){
7720                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7721                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7722                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7723                                                                                                 player[j].skeleton.longdead=0;
7724                                                                                                 player[j].RagDoll(0);
7725                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7726                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7727                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7728                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7729                                                                                                                 Normalise(&flatvelocity2);
7730                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7731                                                                                                         }
7732                                                                                                 }
7733                                                                                         }
7734                                                                                 }
7735                                                                         }
7736
7737                                                                         player[closest].DoDamage(10000);
7738                                                                         player[closest].RagDoll(0);
7739                                                                         player[closest].dead=2;
7740                                                                         player[closest].coords=20;
7741                                                                         player[closest].skeleton.free=2;
7742
7743                                                                         camerashake+=.6;
7744
7745                                                                 }
7746
7747                                                                 explodetogglekeydown=1;
7748                                                 }
7749
7750                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7751                                                         explodetogglekeydown=0;
7752                                                 }
7753
7754                                                 /*
7755                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7756                                                 FILE                    *tfile;
7757                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7758                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7759                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7760                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7761                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7762                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7763                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7764
7765                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7766                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7767                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7768                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7769                                                 for(j=0;j<player[0].num_weapons;j++){
7770                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7771                                                 }
7772                                                 fwrite( &environment, 1, sizeof(int), tfile );
7773
7774                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7775                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7776                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7777                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7778                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7779
7780                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7781                                                 if(numplayers>1&&numplayers<maxplayers)
7782                                                 for(i=1;i<numplayers;i++){
7783                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7784                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7785                                                 for(j=0;j<player[i].num_weapons;j++){
7786                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7787                                                 }
7788                                                 if(player[i].numwaypoints<30){
7789                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7790                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7791                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7792                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7793                                                 }
7794                                                 else{
7795                                                 player[i].numwaypoints=0;
7796                                                 player[i].waypoint=0;
7797                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7798                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7799                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7800                                                 }
7801                                                 }
7802
7803                                                 fclose(tfile);
7804
7805                                                 slomotogglekeydown=1;
7806                                                 }*/
7807
7808                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7809                                                         slomotogglekeydown=0;
7810                                                 }
7811
7812
7813                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7814                                                         player[0].onfire=1-player[0].onfire;
7815                                                         if(player[0].onfire){
7816                                                                 player[0].CatchFire();
7817                                                         }
7818                                                         if(!player[0].onfire){
7819                                                                 float gLoc[3];
7820                                                                 float vel[3];
7821                                                                 gLoc[0]=player[0].coords.x;
7822                                                                 gLoc[1]=player[0].coords.y;
7823                                                                 gLoc[2]=player[0].coords.z;
7824                                                                 vel[0]=0;
7825                                                                 vel[1]=0;
7826                                                                 vel[2]=0;
7827                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
7828                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7829                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
7830                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
7831                                                                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
7832                                                         }
7833                                                         slomotogglekeydown=1;
7834                                                 }
7835                                                 /*
7836                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7837                                                 if(player[0].bleeding<=0)
7838                                                 player[0].DoBlood(1,255);
7839                                                 }*/
7840
7841
7842                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7843                                                         int closest=-1;
7844                                                         float closestdist=-1;
7845                                                         float distance;
7846                                                         if(numplayers>1)
7847                                                                 for(i=1;i<numplayers;i++){
7848                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7849                                                                         if(closestdist==-1||distance<closestdist){
7850                                                                                 closestdist=distance;
7851                                                                                 closest=i;
7852                                                                         }
7853                                                                 }
7854                                                                 if(closestdist>0&&closest>=0){
7855                                                                         //player[closest]=player[numplayers-1];
7856                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7857                                                                         numplayers--;
7858                                                                 }
7859                                                                 drawmodetogglekeydown=1;
7860                                                 }
7861
7862                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7863                                                         int closest=-1;
7864                                                         float closestdist=-1;
7865                                                         float distance;
7866                                                         if(max_objects>1)
7867                                                                 for(i=1;i<max_objects;i++){
7868                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7869                                                                         if(closestdist==-1||distance<closestdist){
7870                                                                                 closestdist=distance;
7871                                                                                 closest=i;
7872                                                                         }
7873                                                                 }
7874                                                                 if(closestdist>0&&closest>=0){
7875                                                                         objects.position[closest].y-=500;
7876                                                                 }
7877                                                                 drawmodetogglekeydown=1;
7878                                                 }
7879
7880                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7881                                                         //drawmode++;
7882                                                         //if(drawmode>2)drawmode=0;
7883                                                         if(objects.numobjects<max_objects-1){                   
7884                                                                 XYZ boxcoords;
7885                                                                 boxcoords.x=player[0].coords.x;
7886                                                                 boxcoords.z=player[0].coords.z;
7887                                                                 boxcoords.y=player[0].coords.y-3;
7888                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7889                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7890                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7891                                                                 float temprotat,temprotat2;
7892                                                                 temprotat=editorrotation;
7893                                                                 temprotat2=editorrotation2;
7894                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7895                                                                 if(temprotat2<0)temprotat2=Random()%360;
7896
7897                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7898                                                                 if(editortype==treetrunktype)
7899                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7900                                                         }
7901
7902                                                         drawmodetogglekeydown=1;
7903                                                 }
7904
7905                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7906                                                         if(numplayers<maxplayers-1){
7907                                                                 player[numplayers].scale=.2*5*player[0].scale;
7908                                                                 player[numplayers].creature=rabbittype;
7909                                                                 player[numplayers].howactive=editoractive;
7910                                                                 player[numplayers].skeleton.id=numplayers;
7911                                                                 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);
7912
7913                                                                 //texsize=512*512*3/texdetail/texdetail;
7914                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7915                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7916
7917                                                                 k=abs(Random()%2)+1;
7918                                                                 if(k==0){
7919                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7920                                                                         player[numplayers].whichskin=0;
7921                                                                 }
7922                                                                 else if(k==1){
7923                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7924                                                                         player[numplayers].whichskin=1;
7925                                                                 }
7926                                                                 else {
7927                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7928                                                                         player[numplayers].whichskin=2;
7929                                                                 }
7930
7931                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7932                                                                 player[numplayers].power=1;
7933                                                                 player[numplayers].speedmult=1;
7934                                                                 player[numplayers].currentanimation=bounceidleanim;
7935                                                                 player[numplayers].targetanimation=bounceidleanim;
7936                                                                 player[numplayers].currentframe=0;
7937                                                                 player[numplayers].targetframe=1;
7938                                                                 player[numplayers].target=0;
7939                                                                 player[numplayers].bled=0;
7940                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
7941
7942                                                                 player[numplayers].targetrotation=player[0].targetrotation;
7943                                                                 player[numplayers].rotation=player[0].rotation;
7944
7945                                                                 player[numplayers].velocity=0;
7946                                                                 player[numplayers].coords=player[0].coords;
7947                                                                 player[numplayers].oldcoords=player[numplayers].coords;
7948                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
7949
7950                                                                 player[numplayers].id=numplayers;
7951                                                                 player[numplayers].skeleton.id=numplayers;
7952                                                                 player[numplayers].updatedelay=0;
7953                                                                 player[numplayers].normalsupdatedelay=0;
7954
7955                                                                 player[numplayers].aitype=passivetype;
7956                                                                 player[numplayers].aitarget=0;
7957
7958                                                                 if(player[0].creature==wolftype){
7959                                                                         headprop=player[0].proportionhead.x/1.1;
7960                                                                         bodyprop=player[0].proportionbody.x/1.1;
7961                                                                         armprop=player[0].proportionarms.x/1.1;
7962                                                                         legprop=player[0].proportionlegs.x/1.1;
7963                                                                 }
7964
7965                                                                 if(player[0].creature==rabbittype){
7966                                                                         headprop=player[0].proportionhead.x/1.2;
7967                                                                         bodyprop=player[0].proportionbody.x/1.05;
7968                                                                         armprop=player[0].proportionarms.x/1.00;
7969                                                                         legprop=player[0].proportionlegs.x/1.1;
7970                                                                 }
7971
7972                                                                 if(player[numplayers].creature==wolftype){
7973                                                                         player[numplayers].proportionhead=1.1*headprop;
7974                                                                         player[numplayers].proportionbody=1.1*bodyprop;
7975                                                                         player[numplayers].proportionarms=1.1*armprop;
7976                                                                         player[numplayers].proportionlegs=1.1*legprop;
7977                                                                 }
7978
7979                                                                 if(player[numplayers].creature==rabbittype){
7980                                                                         player[numplayers].proportionhead=1.2*headprop;
7981                                                                         player[numplayers].proportionbody=1.05*bodyprop;
7982                                                                         player[numplayers].proportionarms=1.00*armprop;
7983                                                                         player[numplayers].proportionlegs=1.1*legprop;
7984                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
7985                                                                 }
7986
7987                                                                 player[numplayers].headless=0;
7988                                                                 player[numplayers].onfire=0;
7989
7990                                                                 if(cellophane){
7991                                                                         player[numplayers].proportionhead.z=0;
7992                                                                         player[numplayers].proportionbody.z=0;
7993                                                                         player[numplayers].proportionarms.z=0;
7994                                                                         player[numplayers].proportionlegs.z=0;
7995                                                                 }
7996
7997                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
7998
7999                                                                 player[numplayers].damagetolerance=200;
8000
8001                                                                 player[numplayers].protectionhead=player[0].protectionhead;
8002                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
8003                                                                 player[numplayers].protectionlow=player[0].protectionlow;
8004                                                                 player[numplayers].armorhead=player[0].armorhead;
8005                                                                 player[numplayers].armorhigh=player[0].armorhigh;
8006                                                                 player[numplayers].armorlow=player[0].armorlow;
8007                                                                 player[numplayers].metalhead=player[0].metalhead;
8008                                                                 player[numplayers].metalhigh=player[0].metalhigh;
8009                                                                 player[numplayers].metallow=player[0].metallow;
8010
8011                                                                 player[numplayers].immobile=player[0].immobile;
8012
8013                                                                 player[numplayers].numclothes=player[0].numclothes;
8014                                                                 if(player[numplayers].numclothes)
8015                                                                         for(i=0;i<player[numplayers].numclothes;i++){
8016                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
8017                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
8018                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
8019                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
8020                                                                                 tintr=player[numplayers].clothestintr[i];
8021                                                                                 tintg=player[numplayers].clothestintg[i];
8022                                                                                 tintb=player[numplayers].clothestintb[i];
8023                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8024                                                                         }
8025                                                                         if(player[numplayers].numclothes){
8026                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
8027                                                                         }
8028
8029                                                                         player[numplayers].power=player[0].power;
8030                                                                         player[numplayers].speedmult=player[0].speedmult;
8031
8032                                                                         player[numplayers].damage=0;
8033                                                                         player[numplayers].permanentdamage=0;
8034                                                                         player[numplayers].superpermanentdamage=0;
8035                                                                         player[numplayers].deathbleeding=0;
8036                                                                         player[numplayers].bleeding=0;
8037                                                                         player[numplayers].numwaypoints=0;
8038                                                                         player[numplayers].waypoint=0;
8039                                                                         player[numplayers].jumppath=0;
8040                                                                         player[numplayers].weaponstuck=-1;
8041                                                                         player[numplayers].weaponactive=-1;
8042                                                                         player[numplayers].num_weapons=0;
8043                                                                         player[numplayers].bloodloss=0;
8044                                                                         player[numplayers].dead=0;
8045
8046                                                                         player[numplayers].loaded=1;
8047
8048                                                                         numplayers++;
8049                                                         }
8050                                                         drawmodetogglekeydown=1;
8051                                                 }
8052
8053                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
8054                                                         if(player[numplayers-1].numwaypoints<90){
8055                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
8056                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
8057                                                                 player[numplayers-1].numwaypoints++;
8058                                                         }
8059                                                         drawmodetogglekeydown=1;
8060                                                 }
8061
8062                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
8063                                                         if(numpathpoints<30){
8064                                                                 bool connected,alreadyconnected;
8065                                                                 connected=0;
8066                                                                 if(numpathpoints>1)
8067                                                                         for(i=0;i<numpathpoints;i++){
8068                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
8069                                                                                         alreadyconnected=0;
8070                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
8071                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
8072                                                                                         }
8073                                                                                         if(!alreadyconnected){
8074                                                                                                 numpathpointconnect[pathpointselected]++;
8075                                                                                                 connected=1;
8076                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
8077                                                                                         }
8078                                                                                 }
8079                                                                         }
8080                                                                         if(!connected){
8081                                                                                 numpathpoints++;
8082                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
8083                                                                                 numpathpointconnect[numpathpoints-1]=0;
8084                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
8085                                                                                         numpathpointconnect[pathpointselected]++;
8086                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
8087                                                                                 }
8088                                                                                 pathpointselected=numpathpoints-1;
8089                                                                         }
8090                                                         }
8091                                                         drawmodetogglekeydown=1;
8092                                                 }
8093
8094                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
8095                                                         pathpointselected++;
8096                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
8097                                                         drawmodetogglekeydown=1;
8098                                                 }
8099                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8100                                                         pathpointselected--;
8101                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
8102                                                         drawmodetogglekeydown=1;
8103                                                 }
8104                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8105                                                         if(pathpointselected!=-1){
8106                                                                 numpathpoints--;
8107                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
8108                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
8109                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
8110                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
8111                                                                 }
8112                                                                 for(i=0;i<numpathpoints;i++){
8113                                                                         for(j=0;j<numpathpointconnect[i];j++){
8114                                                                                 if(pathpointconnect[i][j]==pathpointselected){
8115                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
8116                                                                                         numpathpointconnect[i]--;
8117                                                                                 }
8118                                                                                 if(pathpointconnect[i][j]==numpathpoints){
8119                                                                                         pathpointconnect[i][j]=pathpointselected;
8120                                                                                 }
8121                                                                         }
8122                                                                 }
8123                                                                 pathpointselected=numpathpoints-1;
8124                                                         }
8125                                                         drawmodetogglekeydown=1;
8126                                                 }
8127
8128                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
8129                                                         editorenabled=1-editorenabled;
8130                                                         if(editorenabled){
8131                                                                 player[0].damagetolerance=100000;
8132                                                                 player[0].damage=0;
8133                                                                 player[0].superpermanentdamage=0;
8134                                                                 player[0].bloodloss=0;
8135                                                                 player[0].deathbleeding=0;
8136                                                         }
8137                                                         if(!editorenabled){
8138                                                                 player[0].damagetolerance=200;
8139                                                                 player[0].damage=0;
8140                                                                 player[0].permanentdamage=0;
8141                                                                 player[0].superpermanentdamage=0;
8142                                                                 player[0].bloodloss=0;
8143                                                                 player[0].deathbleeding=0;
8144                                                         }
8145                                                         drawmodetogglekeydown=1;
8146                                                 }
8147
8148                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8149                                                         editortype--;
8150                                                         if(editortype==treeleavestype||editortype==10)editortype--;
8151                                                         if(editortype<0)editortype=firetype;
8152                                                         drawmodetogglekeydown=1;
8153                                                 }
8154
8155                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8156                                                         editortype++;
8157                                                         if(editortype==treeleavestype||editortype==10)editortype++;
8158                                                         if(editortype>firetype)editortype=0;
8159                                                         drawmodetogglekeydown=1;
8160                                                 }
8161
8162                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8163                                                         editorrotation-=multiplier*100;
8164                                                         if(editorrotation<-.01)editorrotation=-.01;
8165                                                         drawmodetogglekeydown=1;
8166                                                 }
8167
8168                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8169                                                         editorrotation+=multiplier*100;
8170                                                         drawmodetogglekeydown=1;
8171                                                 }
8172
8173                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8174                                                         editorsize+=multiplier;
8175                                                         drawmodetogglekeydown=1;
8176                                                 }
8177
8178                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8179                                                         editorsize-=multiplier;
8180                                                         if(editorsize<.1)editorsize=.1;
8181                                                         drawmodetogglekeydown=1;
8182                                                 }
8183
8184
8185                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8186                                                         mapradius-=multiplier*10;
8187                                                 }
8188
8189                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8190                                                         mapradius+=multiplier*10;
8191                                                 }
8192                                                 /*
8193                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8194                                                 mapcenter.x+=multiplier*20;
8195                                                 }
8196
8197                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8198                                                 mapcenter.x-=multiplier*20;
8199                                                 }
8200
8201                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8202                                                 mapcenter.z+=multiplier*20;
8203                                                 }
8204
8205                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8206                                                 mapcenter.z-=multiplier*20;
8207                                                 }
8208                                                 */
8209                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8210                                                         editorrotation2+=multiplier*100;
8211                                                 }
8212
8213                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8214                                                         editorrotation2-=multiplier*100;
8215                                                         if(editorrotation2<-.01)editorrotation2=-.01;
8216                                                 }
8217                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
8218                                                         int closest=-1;
8219                                                         float closestdist=-1;
8220                                                         float distance;
8221                                                         for(i=0;i<objects.numobjects;i++){
8222                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
8223                                                                 if(closestdist==-1||distance<closestdist){
8224                                                                         closestdist=distance;
8225                                                                         closest=i;
8226                                                                 }
8227                                                         }
8228                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);             
8229                                                         drawmodetogglekeydown=1;
8230                                                 }
8231
8232
8233                                                 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)){
8234                                                         drawmodetogglekeydown=0;
8235                                                 }
8236
8237                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8238                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8239                                                         player[0].RagDoll(0);
8240                                                         //player[0].spurt=1;
8241                                                         //player[0].DoDamage(1000);
8242
8243                                                         float gLoc[3];
8244                                                         float vel[3];
8245                                                         gLoc[0]=player[0].coords.x;
8246                                                         gLoc[1]=player[0].coords.y;
8247                                                         gLoc[2]=player[0].coords.z;
8248                                                         vel[0]=player[0].velocity.x;
8249                                                         vel[1]=player[0].velocity.y;
8250                                                         vel[2]=player[0].velocity.z;
8251                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
8252                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8253                                                         FSOUND_SetVolume(channels[whooshsound], 128);
8254                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
8255                                                         //FSOUND_SetPaused(channels[whooshsound], TRUE);
8256
8257                                                         texturesizetogglekeydown=1;
8258                                                 }
8259
8260                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8261
8262                                                         int closest=-1;
8263                                                         float closestdist=-1;
8264                                                         float distance;
8265                                                         for(i=0;i<objects.numobjects;i++){
8266                                                                 if(objects.type[i]==treeleavestype){
8267                                                                         objects.scale[i]*=.9;
8268                                                                 }
8269                                                         }
8270                                                         texturesizetogglekeydown=1;
8271                                                 }
8272
8273                                                 static XYZ relative;
8274                                                 static int randattack;
8275                                                 //Attack
8276                                                 static bool playerrealattackkeydown=0;
8277
8278                                                 if(!buttons[0])oldbutton=0;
8279                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8280                                                 if(oldattackkey)player[0].attackkeydown=0;
8281                                                 if(oldattackkey)playerrealattackkeydown=0;
8282                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8283                                                 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);
8284                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8285                                                         for(k=0;k<numplayers;k++){
8286                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8287                                                                         player[k].Reverse();
8288                                                         }
8289                                                 }
8290
8291                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8292
8293                                                 for(k=0;k<numplayers;k++){
8294                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8295                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8296                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
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                                                                         player[k].jumppower-=2;
8299                                                                 }
8300                                                                 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)){
8301                                                                         for(i=0;i<numplayers;i++){
8302                                                                                 if(i==k)i++;
8303                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8304                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8305                                                                                                 player[k].targetanimation=dodgebackanim;
8306                                                                                                 player[k].target=0;
8307                                                                                                 player[k].targetframe=0;
8308                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8309                                                                                                 Normalise(&rotatetarget);
8310                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8311                                                                                                 player[k].targetrotation*=360/6.28;
8312                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8313
8314                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8315                                                                                         }
8316                                                                         }
8317                                                                         if(player[k].targetanimation!=dodgebackanim){
8318                                                                                 if(k==0)numflipped++;
8319                                                                                 player[k].targetanimation=backhandspringanim;
8320                                                                                 player[k].target=0;
8321                                                                                 player[k].targetframe=0;
8322                                                                                 player[k].targetrotation=-rotation+180;
8323                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8324                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8325                                                                                 player[k].rotation=player[k].targetrotation;
8326                                                                                 player[k].jumppower-=2;
8327                                                                         }
8328                                                                 }
8329                                                                 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())){
8330                                                                         player[k].hasvictim=0;
8331                                                                         if(numplayers>1)
8332                                                                                 for(i=0;i<numplayers;i++){
8333                                                                                         if(i==k)i++;
8334                                                                                         if(!player[k].hasvictim)
8335                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){      
8336                                                                                                         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){
8337                                                                                                                 player[k].victim=&player[i];
8338                                                                                                                 player[k].hasvictim=1;
8339                                                                                                                 if(player[k].aitype==playercontrolled){
8340                                                                                                                         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;
8341                                                                                                                         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;
8342                                                                                                                         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;
8343                                                                                                                         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;
8344                                                                                                                         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;
8345                                                                                                                         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;
8346                                                                                                                         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;
8347                                                                                                                         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;
8348                                                                                                                         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;
8349                                                                                                                         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;
8350                                                                                                                 }
8351                                                                                                                 else {
8352                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8353                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8354                                                                                                                                 else randattack=abs(Random()%5);
8355                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8356                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8357                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8358                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8359                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8360                                                                                                                                 }
8361                                                                                                                                 if(player[k].weaponactive!=-1){
8362                                                                                                                                         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;
8363                                                                                                                                         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;
8364                                                                                                                                         //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;
8365                                                                                                                                         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;
8366                                                                                                                                         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;
8367                                                                                                                                         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;
8368                                                                                                                                         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;
8369                                                                                                                                         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;
8370                                                                                                                                 }
8371                                                                                                                         }
8372                                                                                                                 }
8373                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8374                                                                                                         }
8375                                                                                                         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)){
8376                                                                                                                 if(player[k].weaponactive==-1){
8377                                                                                                                         player[i].targetanimation=sneakattackedanim;
8378                                                                                                                         player[i].currentanimation=sneakattackedanim;
8379                                                                                                                         player[k].currentanimation=sneakattackanim;
8380                                                                                                                         player[k].targetanimation=sneakattackanim;
8381                                                                                                                         player[k].oldcoords=player[k].coords;
8382                                                                                                                         player[k].coords=player[i].coords;
8383                                                                                                                 }
8384                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8385                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8386                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8387                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8388                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8389                                                                                                                         player[i].oldcoords=player[i].coords;
8390                                                                                                                         player[i].coords=player[k].coords;
8391                                                                                                                 }
8392                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8393                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8394                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8395                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8396                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8397                                                                                                                         player[i].oldcoords=player[i].coords;
8398                                                                                                                         player[i].coords=player[k].coords;
8399                                                                                                                 }
8400                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8401                                                                                                                         player[k].victim=&player[i];
8402                                                                                                                         player[k].hasvictim=1;
8403                                                                                                                         player[i].targettilt2=0;
8404                                                                                                                         player[i].targetframe=1;
8405                                                                                                                         player[i].currentframe=0;
8406                                                                                                                         player[i].target=0;
8407                                                                                                                         player[i].velocity=0;
8408                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8409                                                                                                                         player[k].currentframe=player[i].currentframe;
8410                                                                                                                         player[k].targetframe=player[i].targetframe;
8411                                                                                                                         player[k].target=player[i].target;
8412                                                                                                                         player[k].velocity=0;
8413                                                                                                                         player[k].targetrotation=player[i].rotation;
8414                                                                                                                         player[k].rotation=player[i].rotation;
8415                                                                                                                         player[i].targetrotation=player[i].rotation;
8416                                                                                                                 }
8417                                                                                                         }
8418                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8419                                                                                                                 oldattackkey=1;
8420                                                                                                                 player[k].targetframe=0;
8421                                                                                                                 player[k].target=0;
8422                                                                                                                 //player[k].velocity=0;
8423
8424                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8425                                                                                                                 Normalise(&rotatetarget);
8426                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8427                                                                                                                 player[k].targetrotation*=360/6.28;
8428                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8429
8430                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8431
8432                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8433                                                                                                                 player[k].lastattack2=player[k].lastattack;
8434                                                                                                                 player[k].lastattack=player[k].targetanimation;
8435                                                                                                                 //player[k].targettilt2=0;
8436                                                                                                                 //slomo=1;
8437                                                                                                                 //slomodelay=.2;
8438                                                                                                         }
8439                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8440                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8441                                                                                                                 Normalise(&rotatetarget);
8442                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8443                                                                                                                 player[k].targetrotation*=360/6.28;
8444                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8445                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8446                                                                                                                 oldattackkey=1;
8447                                                                                                                 player[k].victim=&player[i];
8448                                                                                                                 player[k].hasvictim=1;
8449                                                                                                                 player[i].targetanimation=knifefollowedanim;
8450                                                                                                                 player[i].currentanimation=knifefollowedanim;
8451                                                                                                                 player[i].targettilt2=0;
8452                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8453                                                                                                                 player[i].targetframe=1;
8454                                                                                                                 player[i].currentframe=0;
8455                                                                                                                 player[i].target=0;
8456                                                                                                                 player[i].velocity=0;
8457                                                                                                                 player[k].currentanimation=knifefollowanim;
8458                                                                                                                 player[k].targetanimation=knifefollowanim;
8459                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8460                                                                                                                 player[k].currentframe=player[i].currentframe;
8461                                                                                                                 player[k].targetframe=player[i].targetframe;
8462                                                                                                                 player[k].target=player[i].target;
8463                                                                                                                 player[k].velocity=0;
8464                                                                                                                 player[k].oldcoords=player[k].coords;
8465                                                                                                                 player[i].coords=player[k].coords;
8466                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8467                                                                                                                 player[i].rotation=player[k].targetrotation;
8468                                                                                                                 player[k].rotation=player[k].targetrotation;
8469                                                                                                                 player[i].rotation=player[k].targetrotation;
8470                                                                                                         }
8471                                                                                                 }
8472                                                                                 }
8473                                                                                 bool hasstaff=0;
8474                                                                                 if(player[k].weaponactive!=-1){
8475                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8476                                                                                 }
8477                                                                                 if(numplayers>1)
8478                                                                                         for(i=0;i<numplayers;i++){
8479                                                                                                 if(i==k)i++;
8480                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){   
8481                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8482                                                                                                                 if(player[i].skeleton.free)
8483                                                                                                                         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)))){
8484                                                                                                                                 player[k].victim=&player[i];
8485                                                                                                                                 player[k].hasvictim=1;
8486                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8487                                                                                                                                         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;
8488                                                                                                                                         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;
8489                                                                                                                                         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;
8490                                                                                                                                 }
8491                                                                                                                                 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){
8492                                                                                                                                         player[k].targetanimation=killanim;
8493                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8494                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8495                                                                                                                                                         terrain.DeleteDecal(j);
8496                                                                                                                                                 }
8497                                                                                                                                         }
8498                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8499                                                                                                                                                 if(objects.model[l].type==decalstype)
8500                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8501                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8502                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8503                                                                                                                                                                 }
8504                                                                                                                                                         }
8505                                                                                                                                         }
8506                                                                                                                                 }
8507                                                                                                                                 if(!player[i].dead||musictype!=2)
8508                                                                                                                                         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)){
8509                                                                                                                                                 player[k].targetanimation=dropkickanim;
8510                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8511                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8512                                                                                                                                                                 terrain.DeleteDecal(j);
8513                                                                                                                                                         }
8514                                                                                                                                                 }
8515                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8516                                                                                                                                                         if(objects.model[l].type==decalstype)
8517                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8518                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8519                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8520                                                                                                                                                                         }
8521                                                                                                                                                                 }
8522                                                                                                                                                 }
8523                                                                                                                                         }
8524                                                                                                                         }
8525                                                                                                                         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)){
8526                                                                                                                                 oldattackkey=1;
8527                                                                                                                                 player[k].targetframe=0;
8528                                                                                                                                 player[k].target=0;
8529                                                                                                                                 //player[k].velocity=0;
8530
8531                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8532                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8533                                                                                                                                         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;
8534                                                                                                                                 }
8535                                                                                                                                 Normalise(&rotatetarget);
8536                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8537                                                                                                                                 player[k].targetrotation*=360/6.28;
8538                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8539
8540                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8541                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8542                                                                                                                                 }
8543
8544                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8545                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8546
8547                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8548                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8549                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8550
8551                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8552                                                                                                                                         player[k].targetrotation+=30;
8553                                                                                                                                 }
8554                                                                                                                                 //player[k].targettilt2=0;
8555                                                                                                                                 //slomo=1;
8556                                                                                                                                 //slomodelay=.2;
8557                                                                                                                         }
8558                                                                                                 }
8559                                                                                         }
8560                                                                                         if(!player[k].hasvictim){
8561                                                                                                 for(i=0;i<numplayers;i++){
8562                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8563                                                                                                                 player[k].victim=&player[i];
8564                                                                                                                 player[k].hasvictim=1;
8565                                                                                                         }
8566                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8567                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8568                                                                                                                         player[k].victim=&player[i];
8569                                                                                                                 }
8570                                                                                                 }
8571                                                                                         }
8572                                                                                         if(player[k].aitype==playercontrolled)
8573                                                                                                 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)){
8574                                                                                                         oldattackkey=1;
8575                                                                                                         player[k].targetanimation=rabbitkickanim;
8576                                                                                                         player[k].targetframe=0;
8577                                                                                                         player[k].target=0;
8578                                                                                                 }
8579                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8580                                                                                                         numattacks++;
8581                                                                                                         bool armedstaff=0;
8582                                                                                                         if(player[k].weaponactive!=-1){
8583                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8584                                                                                                         }
8585                                                                                                         bool armedsword=0;
8586                                                                                                         if(player[k].weaponactive!=-1){
8587                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8588                                                                                                         }
8589                                                                                                         bool armedknife=0;
8590                                                                                                         if(player[k].weaponactive!=-1){
8591                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8592                                                                                                         }
8593                                                                                                         if(armedstaff)numstaffattack++;
8594                                                                                                         else if(armedsword)numswordattack++;
8595                                                                                                         else if(armedknife)numknifeattack++;
8596                                                                                                         else numunarmedattack++;
8597                                                                                                 }
8598                                                                 }
8599                                                         }
8600                                                 }
8601
8602                                                 //Collisions
8603                                                 static float collisionradius;
8604                                                 if(numplayers>1)
8605                                                         for(k=0;k<numplayers;k++){
8606                                                                 for(i=k;i<numplayers;i++){
8607                                                                         if(i==k)i++;
8608                                                                         if(i<numplayers)
8609                                                                                 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))
8610                                                                                         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))
8611                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8612                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8613                                                                                                                 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)
8614                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8615                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8616                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8617                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8618                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8619                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8620                                                                                                                                                                         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)){
8621                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8622                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8623                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8624                                                                                                                                                                                 }       
8625                                                                                                                                                                         }
8626
8627                                                                                                                                                                         tempcoords1=player[i].coords;
8628                                                                                                                                                                         tempcoords2=player[k].coords;
8629                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8630                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8631                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8632                                                                                                                                                                         if(player[0].hasvictim)
8633                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8634                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){   
8635                                                                                                                                                                                 if(k==0)
8636                                                                                                                                                                                         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)){
8637                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8638                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8639                                                                                                                                                                                                 player[i].skeleton.free=0;
8640                                                                                                                                                                                                 player[i].rotation=0;
8641                                                                                                                                                                                                 player[i].RagDoll(0);
8642                                                                                                                                                                                                 player[i].DoDamage(20);
8643                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8644                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8645                                                                                                                                                                                                 player[k].lastcollide=1;        
8646                                                                                                                                                                                         }
8647                                                                                                                                                                                         if(i==0)
8648                                                                                                                                                                                                 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)){
8649                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8650                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8651                                                                                                                                                                                                         player[k].skeleton.free=0;
8652                                                                                                                                                                                                         player[k].rotation=0;
8653                                                                                                                                                                                                         player[k].RagDoll(0);
8654                                                                                                                                                                                                         player[k].DoDamage(20);
8655                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8656                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8657                                                                                                                                                                                                         player[i].lastcollide=1;        
8658                                                                                                                                                                                                 }
8659
8660                                                                                                                                                                                                 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)){     
8661                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8662                                                                                                                                                                                                         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))
8663                                                                                                                                                                                                                 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))){
8664                                                                                                                                                                                                                         //If hit by body
8665                                                                                                                                                                                                                         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)){
8666                                                                                                                                                                                                                                 static float gLoc[3];
8667                                                                                                                                                                                                                                 static float vel[3];
8668                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8669                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8670                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8671                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8672                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8673                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8674                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8675                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, TRUE);
8676                                                                                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8677                                                                                                                                                                                                                                         FSOUND_SetVolume(channels[heavyimpactsound], 256);
8678                                                                                                                                                                                                                                         FSOUND_SetPaused(channels[heavyimpactsound], FALSE);
8679                                                                                                                                                                                                                                 }
8680                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8681                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8682
8683                                                                                                                                                                                                                                 player[i].RagDoll(0);
8684                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8685                                                                                                                                                                                                                                         bonus=aimbonus;
8686                                                                                                                                                                                                                                         bonustime=0;
8687                                                                                                                                                                                                                                         bonusvalue=150;
8688                                                                                                                                                                                                                                 }
8689                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8690                                                                                                                                                                                                                                 player[k].RagDoll(0);
8691                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8692                                                                                                                                                                                                                                         bonus=aimbonus;
8693                                                                                                                                                                                                                                         bonustime=0;
8694                                                                                                                                                                                                                                         bonusvalue=150;
8695                                                                                                                                                                                                                                 }
8696                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8697
8698                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8699                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8700                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8701                                                                                                                                                                                                                                 }
8702                                                                                                                                                                                                                                 //}
8703                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8704                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8705                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8706                                                                                                                                                                                                                                 }
8707                                                                                                                                                                                                                                 //}
8708
8709                                                                                                                                                                                                                         }
8710                                                                                                                                                                                                                 }
8711                                                                                                                                                                                                                 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)){
8712                                                                                                                                                                                                                         //If bumped
8713                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8714                                                                                                                                                                                                                                 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)){
8715                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8716                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8717                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8718                                                                                                                                                                                                                                         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);
8719                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8720                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8721                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8722                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8723                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8724                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8725                                                                                                                                                                                                                                                                 player[k].target=0;
8726                                                                                                                                                                                                                                                         }
8727                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8728                                                                                                                                                                                                                                                         {
8729                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8730                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8731                                                                                                                                                                                                                                                                 player[k].target=0;
8732                                                                                                                                                                                                                                                         }
8733                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8734                                                                                                                                                                                                                                                 }
8735                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8736                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8737                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8738                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8739                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8740                                                                                                                                                                                                                                                                         player[i].target=0;
8741                                                                                                                                                                                                                                                                 }
8742                                                                                                                                                                                                                                                                 else
8743                                                                                                                                                                                                                                                                 {
8744                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8745                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8746                                                                                                                                                                                                                                                                         player[i].target=0;
8747                                                                                                                                                                                                                                                                 }
8748                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8749                                                                                                                                                                                                                                                         }
8750                                                                                                                                                                                                                                 }
8751                                                                                                                                                                                                                                 if(hostile){
8752                                                                                                                                                                                                                                         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){
8753                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8754                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8755                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8756                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8757                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8758                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8759                                                                                                                                                                                                                                                 player[k].lastcollide=1;        
8760                                                                                                                                                                                                                                                 if(k==0){
8761                                                                                                                                                                                                                                                         bonus=AboveBonus;
8762                                                                                                                                                                                                                                                         bonustime=0;
8763                                                                                                                                                                                                                                                         bonusvalue=50;
8764                                                                                                                                                                                                                                                 }
8765                                                                                                                                                                                                                                         }
8766                                                                                                                                                                                                                                         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){
8767                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8768                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8769                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8770                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8771                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8772                                                                                                                                                                                                                                                 player[k].RagDoll(0);   
8773                                                                                                                                                                                                                                                 player[i].lastcollide=1;        
8774                                                                                                                                                                                                                                                 if(i==0){
8775                                                                                                                                                                                                                                                         bonus=AboveBonus;
8776                                                                                                                                                                                                                                                         bonustime=0;
8777                                                                                                                                                                                                                                                         bonusvalue=50;
8778                                                                                                                                                                                                                                                 }
8779                                                                                                                                                                                                                                         }
8780                                                                                                                                                                                                                                 }
8781                                                                                                                                                                                                                         }
8782                                                                                                                                                                                                                 }
8783                                                                                                                                                                                                 }
8784                                                                                                                                                                                                 player[i].CheckKick();
8785                                                                                                                                                                                                 player[k].CheckKick();
8786                                                                                                                                                                         }
8787                                                                                                                                                                 }
8788                                                                 }
8789                                                         }
8790
8791                                                         for(k=0;k<numplayers;k++){
8792                                                                 for(i=k;i<numplayers;i++){
8793                                                                         if(i==k)i++;
8794                                                                         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))){
8795                                                                                 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)){
8796                                                                                         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)){
8797                                                                                                 player[i].victim=&player[k];
8798                                                                                                 player[i].targetanimation=jumpreversedanim;
8799                                                                                                 player[i].currentanimation=jumpreversedanim;
8800                                                                                                 player[k].currentanimation=jumpreversalanim;
8801                                                                                                 player[k].targetanimation=jumpreversalanim;
8802                                                                                                 player[i].targettilt2=0;
8803                                                                                                 player[i].currentframe=0;
8804                                                                                                 player[i].targetframe=1;
8805                                                                                                 player[k].currentframe=0;
8806                                                                                                 player[k].targetframe=1;
8807                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8808                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8809                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8810                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8811                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8812                                                                                                         player[k].currentframe=1;
8813                                                                                                         player[k].targetframe=2;
8814                                                                                                         player[i].currentframe=1;
8815                                                                                                         player[i].targetframe=2;
8816                                                                                                 }
8817                                                                                                 player[k].targettilt2=0;
8818                                                                                                 player[i].target=0;
8819                                                                                                 player[i].velocity=0;
8820                                                                                                 player[k].velocity=0;
8821                                                                                                 player[k].oldcoords=player[k].coords;
8822                                                                                                 player[i].coords=player[k].coords;
8823                                                                                                 player[k].targetrotation=player[i].targetrotation;
8824                                                                                                 player[k].rotation=player[i].targetrotation;
8825                                                                                                 player[k].victim=&player[i];
8826                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8827                                                                                         }
8828                                                                                         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)){
8829                                                                                                 player[k].victim=&player[i];
8830                                                                                                 player[k].targetanimation=jumpreversedanim;
8831                                                                                                 player[k].currentanimation=jumpreversedanim;
8832                                                                                                 player[i].currentanimation=jumpreversalanim;
8833                                                                                                 player[i].targetanimation=jumpreversalanim;
8834                                                                                                 player[k].targettilt2=0;
8835                                                                                                 player[i].targettilt2=0;
8836                                                                                                 player[k].currentframe=0;
8837                                                                                                 player[k].targetframe=1;
8838                                                                                                 player[i].currentframe=0;
8839                                                                                                 player[i].targetframe=1;
8840                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8841                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8842                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8843                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8844                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8845                                                                                                         player[k].currentframe=1;
8846                                                                                                         player[k].targetframe=2;
8847                                                                                                         player[i].currentframe=1;
8848                                                                                                         player[i].targetframe=2;
8849                                                                                                 }
8850                                                                                                 player[k].target=0;
8851                                                                                                 player[k].velocity=0;
8852                                                                                                 player[i].velocity=0;
8853                                                                                                 player[i].oldcoords=player[i].coords;
8854                                                                                                 player[k].coords=player[i].coords;
8855                                                                                                 player[i].targetrotation=player[k].targetrotation;
8856                                                                                                 player[i].rotation=player[k].targetrotation;
8857                                                                                                 player[i].victim=&player[k];
8858                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8859                                                                                         }
8860                                                                                 }
8861                                                                         }
8862                                                                 }
8863                                                         }
8864
8865                                                         for(k=0;k<numplayers;k++)
8866                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8867
8868
8869                                                         //pile
8870                                                         /*
8871                                                         XYZ tempdiff;
8872                                                         XYZ tempoldpos;
8873                                                         XYZ temp1,temp2;
8874                                                         bool isgood;
8875                                                         static float checkdelay;
8876                                                         checkdelay-=multiplier;
8877                                                         int m;
8878                                                         static bool checkedcoll[maxplayers][maxplayers];
8879                                                         static bool above[maxplayers];
8880
8881                                                         for(i=0;i<maxplayers;i++){
8882                                                         for(j=0;j<maxplayers;j++){
8883                                                         checkedcoll[i][j]=0;
8884                                                         }
8885                                                         }
8886
8887                                                         if(numplayers>1&&checkdelay<=0){
8888                                                         checkdelay=.015;
8889                                                         for(k=0;k<numplayers;k++){
8890                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8891
8892                                                         for(i=k;i<numplayers;i++){
8893                                                         if(i==k)i++;
8894                                                         if(i<numplayers)
8895                                                         if(!checkedcoll[i][k]){
8896                                                         checkedcoll[i][k]=1;
8897                                                         checkedcoll[k][i]=1;
8898                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8899                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8900                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8901                                                         if(player[i].coords.y>player[k].coords.y-3)
8902                                                         if(player[i].coords.y<player[k].coords.y+3)
8903                                                         if(player[i].coords.x>player[k].coords.x-3)
8904                                                         if(player[i].coords.x<player[k].coords.x+3)
8905                                                         if(player[i].coords.z>player[k].coords.z-3)
8906                                                         if(player[i].coords.z<player[k].coords.z+3)
8907                                                         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)){
8908                                                         int stuck,moving;
8909                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8910                                                         stuck=i;
8911                                                         moving=k;
8912                                                         }
8913                                                         else
8914                                                         {
8915                                                         moving=i;
8916                                                         stuck=k;
8917                                                         }
8918                                                         isgood=1;
8919
8920                                                         if(isgood){
8921                                                         above[moving]=stuck;
8922                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8923                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8924                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8925                                                         {
8926                                                         player[moving].skeleton.joints[l].position.y+=.003;
8927                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8928
8929                                                         }
8930                                                         }
8931                                                         }
8932                                                         }
8933                                                         }
8934                                                         }
8935                                                         }
8936                                                         }
8937                                                         }
8938
8939                                                         */
8940
8941                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
8942                                                                 texturesizetogglekeydown=0;
8943                                                         }
8944
8945                                                         for(k=0;k<numplayers;k++){
8946                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8947                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8948                                                                                 player[k].DoDamage(1000);
8949                                                                         }
8950                                                                 }
8951                                                         }
8952
8953                                                         static bool respawnkeydown;
8954                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
8955                                                                 targetlevel=whichlevel;
8956                                                                 loading=1;
8957                                                                 leveltime=5;
8958                                                         }
8959                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
8960                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
8961
8962
8963
8964
8965                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
8966                                                                 targetlevel++;
8967                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
8968                                                                 loading=1;
8969                                                                 leveltime=5;
8970                                                                 slomotogglekeydown=1;
8971                                                         }
8972
8973                                                         /*
8974                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
8975                                                         //Respawn
8976                                                         FSOUND_SetPaused(channels[whooshsound], TRUE);
8977                                                         changedelay=0;
8978                                                         for(k=0;k<numplayers;k++){
8979                                                         player[k].dead=0;
8980                                                         player[k].damage=0;
8981                                                         player[k].permanentdamage=0;
8982                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
8983                                                         player[k].aitype=passivetype;
8984                                                         }
8985                                                         player[0].aitype=playercontrolled;
8986                                                         }
8987                                                         */
8988
8989                                                         static bool movekey;
8990                                                         static bool connected;
8991                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
8992                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
8993                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
8994                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
8995                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
8996                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
8997
8998                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
8999
9000                 for(int i=0;i<numplayers;i++){  
9001                                                                 if(!player[i].skeleton.free){
9002                                                                         oldtargetrotation=player[i].targetrotation;
9003                                                                         if(i==0&&indialogue==-1){
9004                                                                                 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){
9005                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
9006                                                                                         if(cameramode)player[0].targetrotation=0;
9007                                                                                 }
9008
9009                                                                                 facing=0;
9010                                                                                 facing.z=-1;
9011
9012                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9013                                                                                 if(cameramode){facing=flatfacing;}
9014                                                                                 else{
9015                                                                                         facing=DoRotation(facing,-rotation2,0,0);
9016                                                                                         facing=DoRotation(facing,0,0-rotation,0);
9017                                                                                 }
9018
9019                                                                                 player[0].lookrotation=-rotation;
9020
9021                                                                                 player[i].targetheadrotation=rotation;
9022                                                                                 player[i].targetheadrotation2=rotation2;                        
9023                                                                         }
9024                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
9025                                                                                 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){
9026                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
9027                                                                                 }
9028
9029                                                                                 facing=0;
9030                                                                                 facing.z=-1;
9031
9032                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9033
9034                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
9035                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
9036
9037                                                                                 player[i].targetheadrotation=player[i].lookrotation;
9038                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;                  
9039                                                                         }
9040                                                                         if(indialogue!=-1){
9041                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
9042                                                                                 Normalise(&rotatetarget);
9043                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
9044                                                                                 player[i].targetheadrotation*=360/6.28;
9045                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9046
9047                                                                                 player[i].targetheadrotation*=-1;
9048                                                                                 player[i].targetheadrotation+=180;
9049                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9050                                                                         }
9051
9052                                                                         bool pause;
9053
9054                                                                         if(leveltime<.5)
9055                                                                                 numenvsounds=0;
9056
9057                                                                         player[i].avoidsomething=0;
9058
9059                                                                         for(j=0;j<objects.numobjects;j++){
9060                                                                                 if(objects.onfire[j]){
9061                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
9062                                                                                         {
9063                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
9064                                                                                                         player[i].collided=0;
9065                                                                                                         player[i].avoidcollided=1;
9066                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9067                                                                                                                 player[i].avoidwhere=objects.position[j];
9068                                                                                                 }
9069                                                                                         }
9070                                                                                 }
9071                                                                         }
9072
9073                                                                         //Add avoidwhere to players
9074
9075                                                                         for(j=0;j<numplayers;j++){
9076                                                                                 if(player[j].onfire){
9077                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
9078                                                                                         {
9079                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
9080                                                                                                         player[i].collided=0;
9081                                                                                                         player[i].avoidcollided=1;
9082                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9083                                                                                                                 player[i].avoidwhere=objects.position[j];
9084                                                                                                 }
9085                                                                                         }
9086                                                                                 }
9087                                                                         }
9088
9089                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
9090                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
9091                                                                                 player[i].jumpclimb=0;
9092                                                                                 //AI
9093                                                                                 if(editorenabled)player[i].stunned=1;
9094
9095                                                                                 player[i].pause=0;
9096                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
9097                                                                                 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;
9098
9099                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
9100                                                                                 player[i].forwardkeydown=0;
9101                                                                                 player[i].leftkeydown=0;
9102                                                                                 player[i].backkeydown=0;
9103                                                                                 player[i].rightkeydown=0;
9104                                                                                 player[i].crouchkeydown=0;
9105                                                                                 player[i].attackkeydown=0;
9106                                                                                 player[i].jumpkeydown=0;
9107                                                                                 player[i].throwkeydown=0;
9108                                                                                 }*/
9109
9110                                                                                 if(player[i].aitype==pathfindtype){
9111                                                                                         if(player[i].finalpathfindpoint==-1){
9112                                                                                                 float closestdistance;
9113                                                                                                 float tempdist;
9114                                                                                                 int closest;
9115                                                                                                 XYZ colpoint;
9116                                                                                                 closest=-1;
9117                                                                                                 closestdistance=-1;
9118                                                                                                 for(j=0;j<numpathpoints;j++){
9119                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
9120                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
9121                                                                                                                 closest=j;
9122                                                                                                                 player[i].finaltarget=pathpoint[j];
9123                                                                                                         }
9124                                                                                                 }
9125                                                                                                 player[i].finalpathfindpoint=closest;
9126                                                                                                 for(j=0;j<numpathpoints;j++){
9127                                                                                                         if(numpathpointconnect[j])
9128                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9129                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9130                                                                                                                         if(tempdist*tempdist<closestdistance){
9131                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9132                                                                                                                                         closestdistance=tempdist*tempdist;
9133                                                                                                                                         closest=j;
9134                                                                                                                                         player[i].finaltarget=colpoint;
9135                                                                                                                                 }
9136                                                                                                                         }
9137                                                                                                                 }
9138                                                                                                 }
9139                                                                                                 player[i].finalpathfindpoint=closest;
9140
9141                                                                                         }
9142                                                                                         if(player[i].targetpathfindpoint==-1){
9143                                                                                                 float closestdistance;
9144                                                                                                 float tempdist;
9145                                                                                                 int closest;
9146                                                                                                 XYZ colpoint;
9147                                                                                                 closest=-1;
9148                                                                                                 closestdistance=-1;
9149                                                                                                 if(player[i].lastpathfindpoint==-1){
9150                                                                                                         for(j=0;j<numpathpoints;j++){
9151                                                                                                                 if(j!=player[i].lastpathfindpoint)
9152                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
9153                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
9154                                                                                                                                 closest=j;
9155                                                                                                                         }
9156                                                                                                         }
9157                                                                                                         player[i].targetpathfindpoint=closest;
9158                                                                                                         for(j=0;j<numpathpoints;j++){
9159                                                                                                                 if(j!=player[i].lastpathfindpoint)
9160                                                                                                                         if(numpathpointconnect[j])
9161                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9162                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9163                                                                                                                                         if(tempdist*tempdist<closestdistance){
9164                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9165                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
9166                                                                                                                                                         closestdistance=tempdist*tempdist;
9167                                                                                                                                                         closest=j;
9168                                                                                                                                                         //}
9169                                                                                                                                                 }
9170                                                                                                                                         }
9171                                                                                                                                 }
9172                                                                                                         }
9173                                                                                                         player[i].targetpathfindpoint=closest;
9174                                                                                                 }
9175                                                                                                 else
9176                                                                                                 {
9177                                                                                                         for(j=0;j<numpathpoints;j++){
9178                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
9179                                                                                                                 {
9180                                                                                                                         connected=0;
9181                                                                                                                         if(numpathpointconnect[j])
9182                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9183                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
9184                                                                                                                                 }
9185                                                                                                                                 if(!connected)
9186                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
9187                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
9188                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
9189                                                                                                                                                 }
9190                                                                                                                                                 if(connected){
9191                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
9192                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
9193                                                                                                                                                                 closestdistance=tempdist;
9194                                                                                                                                                                 closest=j;
9195                                                                                                                                                         }
9196                                                                                                                                                 }
9197                                                                                                                 }
9198                                                                                                         }
9199                                                                                                         player[i].targetpathfindpoint=closest;
9200                                                                                                 }
9201                                                                                         }
9202                                                                                         player[i].losupdatedelay-=multiplier;
9203
9204                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
9205                                                                                         Normalise(&rotatetarget);
9206                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9207                                                                                         player[i].targetrotation*=360/6.28;
9208                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9209                                                                                         player[i].lookrotation=player[i].targetrotation;
9210                                                                                         //player[i].aiupdatedelay=.05;
9211
9212                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
9213                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9214                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9215                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9216                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
9217                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9218                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9219                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9220                                                                                                 player[i].targetpathfindpoint=-1;
9221                                                                                         }
9222                                                                                         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){
9223                                                                                                 player[i].aitype=passivetype;
9224                                                                                         }
9225
9226                                                                                         player[i].forwardkeydown=1;
9227                                                                                         player[i].leftkeydown=0;
9228                                                                                         player[i].backkeydown=0;
9229                                                                                         player[i].rightkeydown=0;
9230                                                                                         player[i].crouchkeydown=0;
9231                                                                                         player[i].attackkeydown=0;
9232                                                                                         player[i].throwkeydown=0;
9233
9234                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9235
9236                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9237                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9238
9239                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9240                                                                                                 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))
9241                                                                                                         player[i].aitype=attacktypecutoff;
9242                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9243                                                                                                         player[i].aitype=attacktypecutoff;
9244
9245                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9246                                                                                                         player[i].losupdatedelay=.2;
9247                                                                                                         for(j=0;j<numplayers;j++){
9248                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9249                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9250                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9251                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9252                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9253                                                                                                                                                         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)){
9254                                                                                                                                                                 player[i].aitype=searchtype;
9255                                                                                                                                                                 player[i].lastchecktime=12;
9256                                                                                                                                                                 player[i].lastseen=player[j].coords;
9257                                                                                                                                                                 player[i].lastseentime=12;
9258                                                                                                                                                         }
9259                                                                                                                 }
9260                                                                                                         }
9261                                                                                                 }
9262                                                                                         }       
9263                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9264                                                                                                 if(player[i].creature!=wolftype){
9265                                                                                                         player[i].stunned=.6;
9266                                                                                                         player[i].surprised=.6;
9267                                                                                                 }
9268                                                                                         }
9269                                                                                 }
9270
9271                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9272                                                                                         player[i].howactive=typeactive;
9273                                                                                 }
9274
9275                                                                                 if(player[i].aitype==passivetype){
9276                                                                                         player[i].aiupdatedelay-=multiplier;
9277                                                                                         player[i].losupdatedelay-=multiplier;
9278                                                                                         player[i].lastseentime+=multiplier;
9279                                                                                         player[i].pausetime-=multiplier;
9280                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9281
9282                                                                                         if(player[i].aiupdatedelay<0){
9283                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9284                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9285                                                                                                         Normalise(&rotatetarget);
9286                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9287                                                                                                         player[i].targetrotation*=360/6.28;
9288                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9289                                                                                                         player[i].lookrotation=player[i].targetrotation;
9290                                                                                                         player[i].aiupdatedelay=.05;
9291
9292                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9293                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9294                                                                                                                 player[i].waypoint++;
9295                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9296
9297                                                                                                         }
9298                                                                                                 }                       
9299
9300                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9301                                                                                                 else player[i].forwardkeydown=0;
9302                                                                                                 player[i].leftkeydown=0;
9303                                                                                                 player[i].backkeydown=0;
9304                                                                                                 player[i].rightkeydown=0;
9305                                                                                                 player[i].crouchkeydown=0;
9306                                                                                                 player[i].attackkeydown=0;
9307                                                                                                 player[i].throwkeydown=0;
9308
9309                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9310                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9311                                                                                                         else{
9312                                                                                                                 XYZ leftpos,rightpos;
9313                                                                                                                 float leftdist,rightdist;
9314                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9315                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9316                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9317                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9318                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9319                                                                                                                 else player[i].targetrotation-=90;
9320                                                                                                         }
9321                                                                                                 }
9322                                                                                         }                       
9323                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9324                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9325
9326
9327                                                                                         if(!editorenabled){
9328                                                                                                 if(player[i].howactive<typesleeping)
9329                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9330                                                                                                                 for(j=0;j<numenvsounds;j++){
9331                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9332                                                                                                                                 player[i].aitype=attacktypecutoff;
9333                                                                                                                         }
9334                                                                                                                 }
9335
9336                                                                                                                 if(player[i].howactive==typesleeping)
9337                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9338                                                                                                                                 for(j=0;j<numenvsounds;j++){
9339                                                                                                                                         if(envsoundvol[j]>14)
9340                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9341                                                                                                                                                         player[i].aitype=attacktypecutoff;
9342                                                                                                                                                 }
9343                                                                                                                                 }
9344
9345                                                                                                                                 if(player[i].aitype!=passivetype){
9346                                                                                                                                         if(player[i].howactive==typesleeping){
9347                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9348                                                                                                                                                 player[i].targetframe=0;
9349                                                                                                                                                 player[i].target=0;
9350                                                                                                                                         }
9351
9352                                                                                                                                         player[i].howactive=typeactive;
9353                                                                                                                                 }
9354                                                                                         }                       
9355
9356                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9357                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9358                                                                                                         player[i].aitype=attacktypecutoff;
9359                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9360                                                                                                         player[i].aitype=attacktypecutoff;
9361
9362                                                                                                 if(player[i].creature==wolftype){
9363                                                                                                         XYZ windsmell;
9364                                                                                                         float smelldistance;
9365                                                                                                         smelldistance=50;
9366                                                                                                         for(j=0;j<numplayers;j++){
9367                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9368                                                                                                                         if(j==0&&player[j].num_weapons>0){
9369                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9370                                                                                                                                 if(player[j].num_weapons==2)
9371                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9372                                                                                                                         }
9373                                                                                                                         if(j!=0){
9374                                                                                                                                 smelldistance=100;
9375                                                                                                                         }
9376                                                                                                                         windsmell=windvector;
9377                                                                                                                         Normalise(&windsmell);
9378                                                                                                                         windsmell=windsmell*2+player[j].coords;
9379                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9380                                                                                                                                 player[i].aitype=attacktypecutoff;
9381                                                                                                                 }
9382                                                                                                         }
9383                                                                                                 }
9384
9385                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9386                                                                                                         player[i].losupdatedelay=.2;
9387                                                                                                         for(j=0;j<numplayers;j++){
9388                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9389                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9390                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9391                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9392                                                                                                                                                 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)){
9393                                                                                                                                                         player[i].lastseentime-=.2;
9394                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9395                                                                                                                                                         else player[i].lastseentime-=.6;                                                                
9396                                                                                                                                                 }
9397                                                                                                                                                 if(player[i].lastseentime<=0){
9398                                                                                                                                                         player[i].aitype=searchtype;
9399                                                                                                                                                         player[i].lastchecktime=12;
9400                                                                                                                                                         player[i].lastseen=player[j].coords;
9401                                                                                                                                                         player[i].lastseentime=12;
9402                                                                                                                                                 }
9403                                                                                                                 }
9404                                                                                                         }
9405                                                                                                 }
9406                                                                                         }
9407                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9408                                                                                                 if(player[i].creature!=wolftype){
9409                                                                                                         player[i].stunned=.6;
9410                                                                                                         player[i].surprised=.6;
9411                                                                                                 }
9412                                                                                                 if(player[i].creature==wolftype){
9413                                                                                                         player[i].stunned=.47;
9414                                                                                                         player[i].surprised=.47;
9415                                                                                                 }
9416                                                                                                 numseen++;
9417                                                                                         }
9418                                                                                 }               
9419
9420                                                                                 if(player[i].aitype==searchtype){
9421                                                                                         player[i].aiupdatedelay-=multiplier;
9422                                                                                         player[i].losupdatedelay-=multiplier;
9423                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9424                                                                                         player[i].lastchecktime-=multiplier;
9425
9426                                                                                         if(player[i].isRun()&&!player[i].onground){
9427                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9428                                                                                                         test2=player[i].coords+player[i].facing;
9429                                                                                                         test2.y+=5;
9430                                                                                                         test=player[i].coords+player[i].facing;
9431                                                                                                         test.y-=10;
9432                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9433                                                                                                         if(j==-1)j=checkcollide(test2,test);
9434                                                                                                         if(j==-1){
9435                                                                                                                 player[i].velocity=0;
9436                                                                                                                 player[i].targetanimation=player[i].getStop();
9437                                                                                                                 player[i].targetframe=0;
9438                                                                                                                 player[i].target=0;
9439                                                                                                                 player[i].targetrotation+=180;
9440                                                                                                                 player[i].stunned=.5;
9441                                                                                                                 //player[i].aitype=passivetype;
9442                                                                                                                 player[i].aitype=pathfindtype;
9443                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9444                                                                                                                 player[i].finalpathfindpoint=-1;
9445                                                                                                                 player[i].targetpathfindpoint=-1;
9446                                                                                                                 player[i].lastpathfindpoint=-1;
9447                                                                                                                 player[i].lastpathfindpoint2=-1;
9448                                                                                                                 player[i].lastpathfindpoint3=-1;
9449                                                                                                                 player[i].lastpathfindpoint4=-1;
9450                                                                                                         }
9451                                                                                                         else player[i].laststanding=j;
9452                                                                                                 }
9453                                                                                         }       
9454                                                                                         if(player[i].aiupdatedelay<0){
9455                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9456                                                                                                 Normalise(&rotatetarget);
9457                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9458                                                                                                 player[i].targetrotation*=360/6.28;
9459                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9460                                                                                                 player[i].lookrotation=player[i].targetrotation;
9461                                                                                                 player[i].aiupdatedelay=.05;
9462                                                                                                 player[i].forwardkeydown=1;
9463
9464                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9465                                                                                                         player[i].forwardkeydown=0;
9466                                                                                                         player[i].aiupdatedelay=1;
9467                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9468                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9469                                                                                                         player[i].lastchecktime=3;
9470                                                                                                 }
9471
9472                                                                                                 player[i].leftkeydown=0;
9473                                                                                                 player[i].backkeydown=0;
9474                                                                                                 player[i].rightkeydown=0;
9475                                                                                                 player[i].crouchkeydown=0;
9476                                                                                                 player[i].attackkeydown=0;
9477                                                                                                 player[i].throwkeydown=0;
9478
9479                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9480                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9481                                                                                                         else{
9482                                                                                                                 XYZ leftpos,rightpos;
9483                                                                                                                 float leftdist,rightdist;
9484                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9485                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9486                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9487                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9488                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9489                                                                                                                 else player[i].targetrotation-=90;
9490                                                                                                         }
9491                                                                                                 }
9492                                                                                         }
9493                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9494                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9495
9496                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9497                                                                                                 for(j=0;j<numenvsounds;j++){
9498                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9499                                                                                                                 player[i].aitype=attacktypecutoff;
9500                                                                                                         }
9501                                                                                                 }
9502
9503                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9504                                                                                                         player[i].losupdatedelay=.2;
9505                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9506                                                                                                         {player[i].aitype=attacktypecutoff;
9507                                                                                                         player[i].lastseentime=1;}
9508                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9509                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9510                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9511                                                                                                                                 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)){
9512                                                                                                                                         player[i].aitype=attacktypecutoff;
9513                                                                                                                                         player[i].lastseentime=1;
9514                                                                                                                                 }
9515                                                                                                 }
9516                                                                                                 if(player[i].lastseentime<0){
9517                                                                                                         //player[i].aitype=passivetype;
9518                                                                                                         numescaped++;
9519                                                                                                         player[i].aitype=pathfindtype;
9520                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9521                                                                                                         player[i].finalpathfindpoint=-1;
9522                                                                                                         player[i].targetpathfindpoint=-1;
9523                                                                                                         player[i].lastpathfindpoint=-1;
9524                                                                                                         player[i].lastpathfindpoint2=-1;
9525                                                                                                         player[i].lastpathfindpoint3=-1;
9526                                                                                                         player[i].lastpathfindpoint4=-1;
9527                                                                                                 }
9528                                                                                 }
9529
9530                                                                                 if(player[i].aitype!=gethelptype){
9531                                                                                         player[i].runninghowlong=0;
9532                                                                                 }
9533
9534                                                                                 if(player[i].aitype==gethelptype){
9535                                                                                         player[i].runninghowlong+=multiplier;
9536                                                                                         player[i].aiupdatedelay-=multiplier;
9537
9538                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9539                                                                                                 player[i].aiupdatedelay=.2;
9540
9541                                                                                                 int closest;
9542                                                                                                 float closestdist;
9543                                                                                                 closest=-1;
9544                                                                                                 closestdist=-1;
9545                                                                                                 float distance;
9546
9547                                                                                                 if(!player[i].ally){
9548                                                                                                         for(j=0;j<numplayers;j++){
9549                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9550                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9551                                                                                                                         if(closestdist==-1||distance<closestdist){
9552                                                                                                                                 closestdist=distance;
9553                                                                                                                                 closest=j;
9554                                                                                                                         }
9555                                                                                                                         closest=j;
9556                                                                                                                 }
9557                                                                                                         }
9558                                                                                                         if(closest!=-1)player[i].ally=closest;
9559                                                                                                         else player[i].ally=0;
9560                                                                                                         player[i].lastseen=player[0].coords;
9561                                                                                                         player[i].lastseentime=12;
9562                                                                                                 }
9563
9564
9565                                                                                                 player[i].lastchecktime=12;
9566                                                                                                 //player[i].lastseentime-=.5;
9567
9568                                                                                                 facing=player[i].coords;
9569                                                                                                 flatfacing=player[player[i].ally].coords;
9570                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9571                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9572                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9573                                                                                                         player[i].lastseentime-=.1;
9574
9575                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9576                                                                                                         player[i].aitype=searchtype;
9577                                                                                                         player[i].lastseentime=12;
9578                                                                                                 }
9579
9580                                                                                                 if(player[i].ally>0){
9581                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9582                                                                                                         Normalise(&rotatetarget);
9583                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9584                                                                                                         player[i].targetrotation*=360/6.28;
9585                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9586                                                                                                         player[i].lookrotation=player[i].targetrotation;
9587                                                                                                         player[i].aiupdatedelay=.05;
9588                                                                                                         player[i].forwardkeydown=1;                                     
9589
9590                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9591                                                                                                                 player[i].aitype=searchtype;
9592                                                                                                                 player[i].lastseentime=12;
9593                                                                                                                 player[player[i].ally].aitype=searchtype;
9594                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9595                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9596                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9597                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9598                                                                                                                 }
9599                                                                                                         }
9600
9601                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9602                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9603                                                                                                                 else{
9604                                                                                                                         XYZ leftpos,rightpos;
9605                                                                                                                         float leftdist,rightdist;
9606                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9607                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9608                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9609                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9610                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9611                                                                                                                         else player[i].targetrotation-=90;
9612                                                                                                                 }
9613                                                                                                         }
9614                                                                                                 }
9615
9616                                                                                                 player[i].leftkeydown=0;
9617                                                                                                 player[i].backkeydown=0;
9618                                                                                                 player[i].rightkeydown=0;
9619                                                                                                 player[i].crouchkeydown=0;
9620                                                                                                 player[i].attackkeydown=0;
9621                                                                                         }
9622                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9623                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9624                                                                                 }
9625
9626                                                                                 if(player[i].aitype==getweapontype){
9627                                                                                         player[i].aiupdatedelay-=multiplier;
9628                                                                                         player[i].lastchecktime-=multiplier;
9629
9630                                                                                         if(player[i].aiupdatedelay<0){
9631                                                                                                 player[i].aiupdatedelay=.2;
9632
9633                                                                                                 int closest;
9634                                                                                                 float closestdist;
9635                                                                                                 closest=-1;
9636                                                                                                 closestdist=-1;
9637                                                                                                 float distance;
9638
9639                                                                                                 if(player[i].ally<0){
9640                                                                                                         for(j=0;j<weapons.numweapons;j++){
9641                                                                                                                 if(weapons.owner[j]==-1){
9642                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9643                                                                                                                         if(closestdist==-1||distance<closestdist){
9644                                                                                                                                 closestdist=distance;
9645                                                                                                                                 closest=j;
9646                                                                                                                         }
9647                                                                                                                         closest=j;
9648                                                                                                                 }
9649                                                                                                         }
9650                                                                                                         if(closest!=-1)player[i].ally=closest;
9651                                                                                                         else player[i].ally=-1;
9652                                                                                                 }
9653
9654                                                                                                 player[i].lastseentime=12;
9655
9656                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9657                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9658                                                                                                                 player[i].aitype=attacktypecutoff;
9659                                                                                                                 player[i].lastseentime=1;
9660                                                                                                         }                                       
9661                                                                                                         if(!player[0].dead)
9662                                                                                                                 if(player[i].ally>=0){
9663                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9664                                                                                                                                 player[i].aitype=attacktypecutoff;
9665                                                                                                                                 player[i].lastseentime=1;
9666                                                                                                                         }
9667                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9668                                                                                                                         Normalise(&rotatetarget);
9669                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9670                                                                                                                         player[i].targetrotation*=360/6.28;
9671                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9672                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9673                                                                                                                         player[i].aiupdatedelay=.05;
9674                                                                                                                         player[i].forwardkeydown=1;                                     
9675
9676
9677                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9678                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9679                                                                                                                                 else{
9680                                                                                                                                         XYZ leftpos,rightpos;
9681                                                                                                                                         float leftdist,rightdist;
9682                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9683                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9684                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9685                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9686                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9687                                                                                                                                         else player[i].targetrotation-=90;
9688                                                                                                                                 }
9689                                                                                                                         }
9690                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9691                                                                                                                         if(abs(Random()%6)){
9692                                                                                                                         player[i].crouchkeydown=1;
9693                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9694                                                                                                                         if(player[i].isRun()){
9695                                                                                                                         player[i].targetframe=0;
9696                                                                                                                         player[i].target=0;
9697                                                                                                                         player[i].targetanimation=sneakanim;
9698                                                                                                                         }
9699                                                                                                                         }
9700                                                                                                                         else player[i].forwardkeydown=0;
9701                                                                                                                         }
9702                                                                                                                         else player[i].crouchkeydown=0;
9703                                                                                                                         }
9704                                                                                                                         else player[i].crouchkeydown=0;*/
9705                                                                                                                 }
9706
9707                                                                                                                 player[i].leftkeydown=0;
9708                                                                                                                 player[i].backkeydown=0;
9709                                                                                                                 player[i].rightkeydown=0;
9710                                                                                                                 player[i].attackkeydown=0;
9711                                                                                                                 player[i].throwkeydown=1;
9712                                                                                                                 player[i].crouchkeydown=0;      
9713                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9714                                                                                                                 player[i].drawkeydown=0;
9715                                                                                         }
9716                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9717                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9718                                                                                 }
9719
9720                                                                                 if(player[i].aitype==attacktypecutoff){
9721                                                                                         player[i].aiupdatedelay-=multiplier;
9722                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9723                                                                                                 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)){
9724                                                                                                         player[i].attackkeydown=0;
9725                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9726                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9727                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9728                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9729                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9730                                                                                                                                 else player[i].targetanimation=rollanim;
9731                                                                                                                                 player[i].target=0;
9732                                                                                                                                 player[i].targetframe=0;
9733                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9734                                                                                                                                 player[i].wentforweapon=0;
9735                                                                                                                         }
9736                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9737                                                                                                                                 player[i].targetanimation=flipanim;
9738                                                                                                                                 player[i].target=0;
9739                                                                                                                                 player[i].targetframe=0;
9740                                                                                                                         }
9741                                                                                                                 }
9742                                                                                                         }
9743                                                                                                         player[i].forwardkeydown=0;
9744                                                                                                         player[i].aiupdatedelay=.02;
9745                                                                                                 }
9746                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9747                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9748                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9749                                                                                                 }
9750                                                                                                 if(player[i].wentforweapon<3)
9751                                                                                                         for(j=0;j<weapons.numweapons;j++){
9752                                                                                                                 if(player[i].creature!=wolftype)
9753                                                                                                                         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){
9754                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9755                                                                                                                                         player[i].wentforweapon++;
9756                                                                                                                                         player[i].lastchecktime=6;
9757                                                                                                                                         player[i].aitype=getweapontype;
9758                                                                                                                                         player[i].ally=-1;
9759                                                                                                                                 }
9760                                                                                                                         }
9761                                                                                                         }
9762                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9763                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9764                                                                                                                         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)))){
9765                                                                                                                                 player[i].crouchkeydown=1;
9766                                                                                                                         }
9767                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9768                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9769                                                                                                                                         test2=player[i].coords+player[i].facing;
9770                                                                                                                                         test2.y+=5;
9771                                                                                                                                         test=player[i].coords+player[i].facing;
9772                                                                                                                                         test.y-=10;
9773                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9774                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9775                                                                                                                                         if(j==-1){
9776                                                                                                                                                 player[i].velocity=0;
9777                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9778                                                                                                                                                 player[i].targetframe=0;
9779                                                                                                                                                 player[i].target=0;
9780                                                                                                                                                 player[i].targetrotation+=180;
9781                                                                                                                                                 player[i].stunned=.5;
9782                                                                                                                                                 //player[i].aitype=passivetype;
9783                                                                                                                                                 player[i].aitype=pathfindtype;
9784                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9785                                                                                                                                                 player[i].finalpathfindpoint=-1;
9786                                                                                                                                                 player[i].targetpathfindpoint=-1;
9787                                                                                                                                                 player[i].lastpathfindpoint=-1;
9788                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9789                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9790                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9791                                                                                                                                         }
9792                                                                                                                                         else player[i].laststanding=j;
9793                                                                                                                                 }
9794                                                                                                                         }
9795                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9796                                                                                                                                 player[i].aitype=pathfindtype;
9797                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9798                                                                                                                                 player[i].finalpathfindpoint=-1;
9799                                                                                                                                 player[i].targetpathfindpoint=-1;
9800                                                                                                                                 player[i].lastpathfindpoint=-1;
9801                                                                                                                                 player[i].lastpathfindpoint2=-1;
9802                                                                                                                                 player[i].lastpathfindpoint3=-1;
9803                                                                                                                                 player[i].lastpathfindpoint4=-1;
9804                                                                                                                         }       
9805                                                                                                                         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){
9806                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9807                                                                                                                                 else player[i].drawkeydown=0;
9808                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9809                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9810                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9811                                                                                                                                         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;
9812                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9813                                                                                                                                 Normalise(&rotatetarget);
9814                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9815                                                                                                                                 player[i].targetrotation*=360/6.28;
9816                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9817                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9818                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9819
9820                                                                                                                                 oldkey=player[i].forwardkeydown;
9821                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9822                                                                                                                                 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;
9823                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9824                                                                                                                                 else player[i].forwardkeydown=0;
9825                                                                                                                                 if(player[0].dead){
9826                                                                                                                                         player[i].forwardkeydown=0;
9827                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9828                                                                                                                                         if(Random()%100==0){
9829                                                                                                                                                 player[i].aitype=pathfindtype;
9830                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9831                                                                                                                                                 player[i].finalpathfindpoint=-1;
9832                                                                                                                                                 player[i].targetpathfindpoint=-1;
9833                                                                                                                                                 player[i].lastpathfindpoint=-1;
9834                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9835                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9836                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9837                                                                                                                                         }
9838                                                                                                                                 }
9839                                                                                                                                 player[i].leftkeydown=0;
9840                                                                                                                                 player[i].backkeydown=0;
9841                                                                                                                                 player[i].rightkeydown=0;
9842                                                                                                                                 player[i].crouchkeydown=0;
9843                                                                                                                                 player[i].throwkeydown=0;
9844
9845                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9846                                                                                                                                 /*for(j=0;j<numplayers;j++){
9847                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9848                                                                                                                                 player[i].crouchkeydown=1;
9849                                                                                                                                 }
9850                                                                                                                                 }*/
9851                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9852                                                                                                                                 else player[i].attackkeydown=0;
9853                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9854                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9855                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9856                                                                                                                                 player[i].attackkeydown=0;
9857                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9858                                                                                                                                 player[i].forwardkeydown=0;
9859                                                                                                                                 player[i].aiupdatedelay=.02;
9860                                                                                                                                 }*/
9861
9862                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9863                                                                                                                                         target=-2;
9864                                                                                                                                         for(j=0;j<numplayers;j++){
9865                                                                                                                                                 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)){
9866                                                                                                                                                         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))))){
9867                                                                                                                                                                 if(target>=0)target=-1;
9868                                                                                                                                                                 else target=j;
9869                                                                                                                                                         }
9870                                                                                                                                                 }
9871                                                                                                                                         }
9872                                                                                                                                         if(target>=0)player[target].Reverse();
9873                                                                                                                                 }
9874
9875                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9876                                                                                                                                 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;
9877                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9878                                                                                                                                         player[0].jumpkeydown=0;
9879                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9880                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9881                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9882
9883                                                                                                                                 if(tutoriallevel==1){
9884                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9885                                                                                                                                 }
9886
9887
9888                                                                                                                                 facing=player[i].coords;
9889                                                                                                                                 flatfacing=player[0].coords;
9890                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9891                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9892                                                                                                                                 if(player[i].occluded>=2)
9893                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9894                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9895                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9896                                                                                                                                                         player[i].aitype=searchtype;
9897                                                                                                                                                         player[i].lastchecktime=12;
9898                                                                                                                                                         player[i].lastseen=player[0].coords;
9899                                                                                                                                                         player[i].lastseentime=12;
9900                                                                                                                                                 }
9901                                                                                                                                         }
9902                                                                                                                                         else player[i].lastseentime=1;
9903                                                                                                                         }
9904                                                                                 }
9905                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9906                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9907                                                                                                 test=player[0].coords;
9908                                                                                                 test.y-=40;
9909                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9910                                                                                         }
9911                                                                                 }
9912                                                                                 // NOTE: Ask about logic of this call : NOTE
9913                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9914                                                                                         player[i].stunned>0 ||
9915                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9916                                                                                 {
9917                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9918                                                                                         player[i].targetrotation=player[i].rotation;
9919                                                                                         player[i].forwardkeydown=0;
9920                                                                                         player[i].leftkeydown=0;
9921                                                                                         player[i].backkeydown=0;
9922                                                                                         player[i].rightkeydown=0;
9923                                                                                         player[i].jumpkeydown=0;
9924                                                                                         player[i].attackkeydown=0;
9925                                                                                         player[i].crouchkeydown=0;
9926                                                                                         player[i].throwkeydown=0;
9927                                                                                 }
9928
9929
9930                                                                                 facing=0;
9931                                                                                 facing.z=-1;
9932
9933                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9934                                                                                 facing=flatfacing;
9935
9936                                                                                 if(player[i].aitype==attacktypecutoff){
9937                                                                                         rotatetarget=player[0].coords-player[i].coords;
9938                                                                                         Normalise(&rotatetarget);
9939                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9940                                                                                         player[i].targetheadrotation*=360/6.28;
9941                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9942
9943                                                                                         player[i].targetheadrotation*=-1;
9944                                                                                         player[i].targetheadrotation+=180;
9945                                                                                         //player[i].targetheadrotation2=0;
9946                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9947                                                                                 }
9948                                                                                 else if(player[i].howactive>=typesleeping){
9949                                                                                         player[i].targetheadrotation=player[i].targetrotation;
9950                                                                                         player[i].targetheadrotation2=0;
9951                                                                                 }
9952                                                                                 else {
9953                                                                                         if(player[i].interestdelay<=0){
9954                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
9955                                                                                                 player[i].headtarget=player[i].coords;
9956                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
9957                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
9958                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
9959                                                                                                 player[i].headtarget+=player[i].facing*1.5;
9960                                                                                         }
9961                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
9962                                                                                         Normalise(&rotatetarget);
9963                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9964                                                                                         player[i].targetheadrotation*=360/6.28;
9965                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9966
9967                                                                                         player[i].targetheadrotation*=-1;
9968                                                                                         player[i].targetheadrotation+=180;
9969                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9970                                                                                 }
9971                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
9972                                                                         }
9973                                                                         if(animation[player[i].targetanimation].attack==reversed){
9974                                                                                 //player[i].targetrotation=player[i].rotation;
9975                                                                                 player[i].forwardkeydown=0;
9976                                                                                 player[i].leftkeydown=0;
9977                                                                                 player[i].backkeydown=0;
9978                                                                                 player[i].rightkeydown=0;
9979                                                                                 player[i].jumpkeydown=0;
9980                                                                                 player[i].attackkeydown=0;
9981                                                                                 //player[i].crouchkeydown=0;
9982                                                                                 player[i].throwkeydown=0;
9983                                                                         }
9984
9985                                                                         if(indialogue!=-1){
9986                                                                                 player[i].forwardkeydown=0;
9987                                                                                 player[i].leftkeydown=0;
9988                                                                                 player[i].backkeydown=0;
9989                                                                                 player[i].rightkeydown=0;
9990                                                                                 player[i].jumpkeydown=0;
9991                                                                                 player[i].crouchkeydown=0;
9992                                                                                 player[i].drawkeydown=0;
9993                                                                                 player[i].throwkeydown=0;
9994                                                                         }
9995
9996                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
9997                                                                         if(player[i].collided>1)player[i].collided=1;
9998                                                                         player[i].collided-=multiplier*4;
9999                                                                         player[i].whichdirectiondelay-=multiplier;
10000                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
10001                                                                                 player[i].avoidcollided=-.3;
10002                                                                                 player[i].whichdirection=abs(Random()%2);
10003                                                                                 player[i].whichdirectiondelay=.4;
10004                                                                         }
10005                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
10006                                                                         player[i].avoidcollided-=multiplier/4;
10007                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
10008                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
10009                                                                         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;
10010
10011                                                                         if(!player[i].throwkeydown){
10012                                                                                 player[i].throwtogglekeydown=0;
10013                                                                         }
10014                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
10015                                                                                 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)){
10016                                                                                         for(j=0;j<weapons.numweapons;j++){
10017                                                                                                 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)
10018                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
10019                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
10020                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
10021                                                                                                                                 player[i].throwtogglekeydown=1;
10022                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10023                                                                                                                                 player[i].target=0;
10024                                                                                                                                 player[i].targetframe=0;
10025                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10026                                                                                                                                 Normalise(&rotatetarget);
10027                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10028                                                                                                                                 player[i].targetrotation*=360/6.28;
10029                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10030                                                                                                                                 player[i].hasvictim=0;
10031                                                                                                                         }
10032                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10033                                                                                                                                 player[i].throwtogglekeydown=1;
10034                                                                                                                                 player[i].hasvictim=0;
10035
10036                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
10037                                                                                                                                 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))
10038                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
10039                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
10040                                                                                                                                                         float gLoc[3];
10041                                                                                                                                                         float vel[3];
10042                                                                                                                                                         gLoc[0]=player[i].coords.x;
10043                                                                                                                                                         gLoc[1]=player[i].coords.y;
10044                                                                                                                                                         gLoc[2]=player[i].coords.z;
10045                                                                                                                                                         vel[0]=player[i].velocity.x;
10046                                                                                                                                                         vel[1]=player[i].velocity.y;
10047                                                                                                                                                         vel[2]=player[i].velocity.z;
10048                                                                                                                                                         if(weapons.type[j]!=staff){
10049                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10050                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10051                                                                                                                                                                 FSOUND_SetVolume(channels[knifedrawsound], 128);
10052                                                                                                                                                                 FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10053                                                                                                                                                         }
10054
10055                                                                                                                                                         player[i].weaponactive=0;
10056                                                                                                                                                         weapons.owner[j]=player[i].id;
10057                                                                                                                                                         if(player[i].num_weapons>0){
10058                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10059                                                                                                                                                         }
10060                                                                                                                                                         player[i].num_weapons++;
10061                                                                                                                                                         player[i].weaponids[0]=j;
10062                                                                                                                                                 }
10063                                                                                                                                         }
10064                                                                                                                                         //}
10065                                                                                                                         }
10066                                                                                                                 }
10067                                                                                                                 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){
10068                                                                                                                         if(!player[i].isFlip()){
10069                                                                                                                                 player[i].throwtogglekeydown=1;
10070                                                                                                                                 player[i].targetanimation=removeknifeanim;
10071                                                                                                                                 player[i].target=0;
10072                                                                                                                                 player[i].targetframe=0;
10073                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10074                                                                                                                                 Normalise(&rotatetarget);
10075                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10076                                                                                                                                 player[i].targetrotation*=360/6.28;
10077                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10078                                                                                                                         }
10079                                                                                                                         if(player[i].isFlip()){
10080                                                                                                                                 player[i].throwtogglekeydown=1;
10081                                                                                                                                 player[i].hasvictim=0;
10082
10083                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
10084                                                                                                                                         if(player[i].weaponactive==-1)
10085                                                                                                                                                 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))
10086                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
10087                                                                                                                                                                 float gLoc[3];
10088                                                                                                                                                                 float vel[3];
10089                                                                                                                                                                 gLoc[0]=player[i].coords.x;
10090                                                                                                                                                                 gLoc[1]=player[i].coords.y;
10091                                                                                                                                                                 gLoc[2]=player[i].coords.z;
10092                                                                                                                                                                 vel[0]=player[i].velocity.x;
10093                                                                                                                                                                 vel[1]=player[i].velocity.y;
10094                                                                                                                                                                 vel[2]=player[i].velocity.z;
10095                                                                                                                                                                 if(weapons.type[k]!=staff){
10096                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10097                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10098                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10099                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10100                                                                                                                                                                 }
10101
10102                                                                                                                                                                 player[i].weaponactive=0;
10103                                                                                                                                                                 weapons.owner[k]=player[i].id;
10104                                                                                                                                                                 if(player[i].num_weapons>0){
10105                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10106                                                                                                                                                                 }
10107                                                                                                                                                                 player[i].num_weapons++;
10108                                                                                                                                                                 player[i].weaponids[0]=k;
10109                                                                                                                                                         }
10110                                                                                                                                 }
10111                                                                                                                         }
10112                                                                                                                 }
10113                                                                                                         }
10114                                                                                         }
10115                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10116                                                                                                 if(numplayers>1)
10117                                                                                                         for(j=0;j<numplayers;j++){
10118                                                                                                                 if(player[i].weaponactive==-1)
10119                                                                                                                         if(j!=i)
10120                                                                                                                                 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)){
10121                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
10122                                                                                                                                                 player[i].throwtogglekeydown=1;
10123                                                                                                                                                 player[i].victim=&player[j];
10124                                                                                                                                                 player[i].hasvictim=1;
10125                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10126                                                                                                                                                 player[i].target=0;
10127                                                                                                                                                 player[i].targetframe=0;
10128                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10129                                                                                                                                                 Normalise(&rotatetarget);
10130                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10131                                                                                                                                                 player[i].targetrotation*=360/6.28;
10132                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10133                                                                                                                                         }
10134                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10135                                                                                                                                                 player[i].throwtogglekeydown=1;
10136                                                                                                                                                 player[i].victim=&player[j];
10137                                                                                                                                                 player[i].hasvictim=1;
10138                                                                                                                                                 int k = player[j].weaponids[0];
10139                                                                                                                                                 if(player[i].hasvictim){
10140                                                                                                                                                         float gLoc[3];
10141                                                                                                                                                         float vel[3];
10142                                                                                                                                                         gLoc[0]=player[i].coords.x;
10143                                                                                                                                                         gLoc[1]=player[i].coords.y;
10144                                                                                                                                                         gLoc[2]=player[i].coords.z;
10145                                                                                                                                                         vel[0]=player[i].velocity.x;
10146                                                                                                                                                         vel[1]=player[i].velocity.y;
10147                                                                                                                                                         vel[2]=player[i].velocity.z;
10148                                                                                                                                                         bool fleshstuck;
10149                                                                                                                                                         fleshstuck=0;
10150                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
10151                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10152                                                                                                                                                                         fleshstuck=1;
10153                                                                                                                                                                 }
10154                                                                                                                                                         }
10155                                                                                                                                                         if(!fleshstuck){
10156                                                                                                                                                                 if(weapons.type[k]!=staff){
10157                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10158                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10159                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10160                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10161                                                                                                                                                                 }
10162                                                                                                                                                         }
10163                                                                                                                                                         if(fleshstuck){
10164                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, TRUE);
10165                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
10166                                                                                                                                                                 FSOUND_SetVolume(channels[fleshstabremovesound], 128);
10167                                                                                                                                                                 FSOUND_SetPaused(channels[fleshstabremovesound], FALSE);
10168                                                                                                                                                         }
10169
10170                                                                                                                                                         player[i].weaponactive=0;
10171                                                                                                                                                         if(weapons.owner[k]!=-1){
10172                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
10173                                                                                                                                                                 else player[i].victim->num_weapons=1;
10174
10175                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
10176                                                                                                                                                                 player[i].victim->skeleton.free=1;
10177                                                                                                                                                                 player[i].victim->skeleton.broken=0;
10178
10179                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
10180                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
10181                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
10182                                                                                                                                                                 }
10183
10184                                                                                                                                                                 XYZ relative;
10185                                                                                                                                                                 relative=0;
10186                                                                                                                                                                 relative.y=10;
10187                                                                                                                                                                 Normalise(&relative);
10188                                                                                                                                                                 XYZ footvel,footpoint;
10189                                                                                                                                                                 footvel=0;
10190                                                                                                                                                                 footpoint=weapons.position[k];
10191                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
10192                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10193                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
10194                                                                                                                                                                                 weapons.bloody[k]=2;
10195                                                                                                                                                                                 weapons.blooddrip[k]=5;
10196                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
10197                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
10198                                                                                                                                                                                 player[i].victim->DoDamage(2000);
10199                                                                                                                                                                         }
10200                                                                                                                                                                 }
10201                                                                                                                                                                 if(player[i].victim->num_weapons>0){
10202                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
10203                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
10204                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
10205                                                                                                                                                                 }
10206
10207                                                                                                                                                                 player[i].victim->weaponactive=-1;
10208
10209                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
10210                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
10211                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
10212                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
10213                                                                                                                                                         }
10214                                                                                                                                                         weapons.owner[k]=i;
10215                                                                                                                                                         if(player[i].num_weapons>0){
10216                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10217                                                                                                                                                         }
10218                                                                                                                                                         player[i].num_weapons++;
10219                                                                                                                                                         player[i].weaponids[0]=k;
10220                                                                                                                                                 }
10221                                                                                                                                         }
10222                                                                                                                                 }
10223                                                                                                         }
10224                                                                                         }
10225                                                                                 }
10226                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10227                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
10228                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
10229                                                                                                         if(numplayers>1)
10230                                                                                                                 for(j=0;j<numplayers;j++){
10231                                                                                                                         if(i!=j)
10232                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
10233                                                                                                                                         if(hostile)
10234                                                                                                                                                 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)){
10235                                                                                                                                                         if(!player[i].isFlip()){
10236                                                                                                                                                                 player[i].throwtogglekeydown=1;
10237                                                                                                                                                                 player[i].victim=&player[j];
10238                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10239                                                                                                                                                                 player[i].target=0;
10240                                                                                                                                                                 player[i].targetframe=0;
10241                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10242                                                                                                                                                                 Normalise(&rotatetarget);
10243                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10244                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10245                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10246
10247                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10248                                                                                                                                                         }
10249                                                                                                                                                         if(player[i].isFlip()){
10250                                                                                                                                                                 if(player[i].weaponactive!=-1){
10251                                                                                                                                                                         player[i].throwtogglekeydown=1;
10252                                                                                                                                                                         player[i].victim=&player[j];
10253                                                                                                                                                                         XYZ aim;
10254                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10255                                                                                                                                                                         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);                                                
10256                                                                                                                                                                         Normalise(&aim);
10257
10258                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10259
10260                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10261                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10262                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10263                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10264                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10265                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10266                                                                                                                                                                         player[i].num_weapons--;
10267                                                                                                                                                                         if(player[i].num_weapons){
10268                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10269                                                                                                                                                                         }
10270                                                                                                                                                                         player[i].weaponactive=-1;
10271                                                                                                                                                                 }               
10272                                                                                                                                                         }
10273                                                                                                                                                 }
10274                                                                                                                 }
10275                                                                                         }
10276                                                                                 }
10277                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10278                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10279                                                                                         {
10280                                                                                                 player[i].throwtogglekeydown=1;
10281                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10282                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10283                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10284                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10285                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10286                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10287                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10288                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10289                                                                                                 player[i].num_weapons--;
10290                                                                                                 if(player[i].num_weapons){
10291                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10292                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10293                                                                                                 }
10294
10295                                                                                                 player[i].weaponactive=-1;
10296                                                                                                 for(j=0;j<numplayers;j++){
10297                                                                                                         player[j].wentforweapon=0;
10298                                                                                                 }
10299                                                                                         }
10300                                                                                 }
10301
10302                                                                         }
10303
10304                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10305                                                                                 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)){
10306                                                                                         //Setenvironment(1-environment);
10307                                                                                         bool isgood;
10308                                                                                         isgood=1;
10309                                                                                         if(player[i].weaponactive!=-1){
10310                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10311                                                                                         }
10312                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10313                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10314                                                                                                         player[i].targetanimation=drawrightanim;
10315                                                                                                         player[i].targetframe=0;
10316                                                                                                         player[i].target=0;
10317                                                                                                         player[i].drawtogglekeydown=1;
10318                                                                                                 }
10319                                                                                                 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){
10320                                                                                                         player[i].targetanimation=drawleftanim;
10321                                                                                                         player[i].targetframe=0;
10322                                                                                                         player[i].target=0;
10323                                                                                                         player[i].drawtogglekeydown=1;
10324                                                                                                 }
10325                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10326                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10327                                                                                                         player[i].targetframe=0;
10328                                                                                                         player[i].target=0;
10329                                                                                                         player[i].drawtogglekeydown=1;
10330                                                                                                 }
10331                                                                                         }                        
10332                                                                                 }
10333                                                                                 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){
10334                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10335                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10336                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10337                                                                                                 player[i].targetframe=0;
10338                                                                                                 player[i].target=0;
10339                                                                                                 player[i].hasvictim=0;
10340                                                                                                 //player[i].attacktogglekeydown=1;
10341                                                                                         }
10342                                                                                 }
10343
10344                                                                                 if(!player[i].drawkeydown){
10345                                                                                         player[i].drawtogglekeydown=0;
10346                                                                                 }
10347
10348                                                                                 if(i==0){
10349                                                                                         absflatfacing=0;
10350                                                                                         absflatfacing.z=-1;
10351
10352                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10353                                                                                 }
10354                                                                                 else absflatfacing=flatfacing;
10355
10356                                                                                 if(indialogue!=-1){
10357                                                                                         player[i].forwardkeydown=0;
10358                                                                                         player[i].leftkeydown=0;
10359                                                                                         player[i].backkeydown=0;
10360                                                                                         player[i].rightkeydown=0;
10361                                                                                         player[i].jumpkeydown=0;
10362                                                                                         player[i].crouchkeydown=0;
10363                                                                                         player[i].drawkeydown=0;
10364                                                                                         player[i].throwkeydown=0;
10365                                                                                 }
10366                                                                                 movekey=0;
10367                                                                                 //Do controls
10368                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10369                                                                                         if(!player[i].forwardkeydown){
10370                                                                                                 player[i].forwardstogglekeydown=0;
10371                                                                                         }
10372                                                                                         if(player[i].crouchkeydown){
10373                                                                                                 //Crouch
10374                                                                                                 target=-2;
10375                                                                                                 if(i==0){
10376                                                                                                         player[i].superruntoggle=1;
10377                                                                                                         if(numplayers>1)
10378                                                                                                                 for(j=0;j<numplayers;j++){
10379                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10380                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10381                                                                                                                                         player[i].superruntoggle=0;
10382                                                                                                                                 }
10383                                                                                                                         }
10384                                                                                                                 }
10385                                                                                                 }
10386
10387                                                                                                 if(numplayers>1)
10388                                                                                                         for(j=0;j<numplayers;j++){
10389                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10390                                                                                                                         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))){
10391                                                                                                                                 if(target>=0)target=-1;
10392                                                                                                                                 else target=j;
10393                                                                                                                         }
10394                                                                                                                 }
10395                                                                                                         }
10396                                                                                                         if(target>=0)player[target].Reverse();
10397                                                                                                         player[i].lowreversaldelay=.5;
10398
10399                                                                                                         if(player[i].isIdle()){
10400                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10401                                                                                                                 player[i].target=0;
10402                                                                                                                 player[i].targetframe=0;
10403                                                                                                                 player[i].transspeed=10;
10404                                                                                                         }
10405                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10406                                                                                                                 player[i].targetanimation=rollanim;
10407                                                                                                                 player[i].target=0;
10408                                                                                                                 player[i].targetframe=0;
10409                                                                                                                 player[i].transspeed=20;
10410                                                                                                         }
10411                                                                                         }
10412                                                                                         if(!player[i].crouchkeydown){
10413                                                                                                 //Uncrouch
10414                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10415                                                                                                 target=-2;
10416                                                                                                 if(player[i].isCrouch()){
10417                                                                                                         if(numplayers>1)
10418                                                                                                                 for(j=0;j<numplayers;j++){
10419                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10420                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10421                                                                                                                                         if(target>=0)target=-1;
10422                                                                                                                                         else target=j;
10423                                                                                                                                 }
10424                                                                                                                         }
10425                                                                                                                 }
10426                                                                                                                 if(target>=0)player[target].Reverse();
10427                                                                                                                 player[i].highreversaldelay=.5;
10428
10429                                                                                                                 if(player[i].isCrouch()){                                               
10430                                                                                                                         if(!player[i].wasCrouch()){
10431                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10432                                                                                                                                 player[i].currentframe=0;
10433                                                                                                                         }
10434                                                                                                                         player[i].target=0;
10435                                                                                                                         player[i].targetanimation=player[i].getIdle();
10436                                                                                                                         player[i].targetframe=0;
10437                                                                                                                         player[i].transspeed=10;
10438                                                                                                                 }
10439                                                                                                 }
10440                                                                                                 if(player[i].targetanimation==sneakanim){
10441                                                                                                         player[i].targetanimation=player[i].getIdle();
10442                                                                                                         player[i].target=0;
10443                                                                                                         player[i].targetframe=0;
10444                                                                                                         player[i].transspeed=10;
10445                                                                                                 }
10446                                                                                         }
10447                                                                                         if(player[i].forwardkeydown){
10448                                                                                                 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)){
10449                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10450                                                                                                         else player[i].targetanimation=player[i].getRun();
10451                                                                                                         player[i].target=0;
10452                                                                                                         player[i].targetframe=0;
10453                                                                                                 }
10454                                                                                                 if(player[i].isCrouch()){
10455                                                                                                         player[i].targetanimation=sneakanim;
10456                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10457                                                                                                         player[i].targetframe=0;
10458                                                                                                 }
10459                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10460                                                                                                         player[i].targetanimation=climbanim;
10461                                                                                                         player[i].target=0;
10462                                                                                                         player[i].targetframe=1;
10463                                                                                                         player[i].jumpclimb=1;
10464                                                                                                 }
10465                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10466                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10467                                                                                                 }
10468                                                                                                 player[i].forwardstogglekeydown=1;
10469                                                                                                 movekey=1;
10470                                                                                         }
10471                                                                                         if (player[i].rightkeydown){
10472                                                                                                 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)){
10473                                                                                                         player[i].targetanimation=player[i].getRun();
10474                                                                                                         player[i].target=0;
10475                                                                                                         player[i].targetframe=0;
10476                                                                                                 }
10477                                                                                                 if(player[i].isCrouch()){
10478                                                                                                         player[i].targetanimation=sneakanim;
10479                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10480                                                                                                         player[i].targetframe=0;
10481                                                                                                 }
10482                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10483                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10484                                                                                                 }
10485                                                                                                 player[i].targetrotation-=90;
10486                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10487                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10488                                                                                                 movekey=1;
10489                                                                                         }
10490                                                                                         if ( player[i].leftkeydown){
10491                                                                                                 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)){
10492                                                                                                         player[i].targetanimation=player[i].getRun();
10493                                                                                                         player[i].target=0;
10494                                                                                                         player[i].targetframe=0;
10495                                                                                                 }
10496                                                                                                 if(player[i].isCrouch()){
10497                                                                                                         player[i].targetanimation=sneakanim;
10498                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10499                                                                                                         player[i].targetframe=0;
10500                                                                                                 }
10501                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10502                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10503                                                                                                 }
10504                                                                                                 player[i].targetrotation+=90;
10505                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10506                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10507                                                                                                 movekey=1;
10508                                                                                         }
10509                                                                                         if(player[i].backkeydown){
10510                                                                                                 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)){
10511                                                                                                         player[i].targetanimation=player[i].getRun();
10512                                                                                                         player[i].target=0;
10513                                                                                                         player[i].targetframe=0;
10514                                                                                                 }
10515                                                                                                 if(player[i].isCrouch()){
10516                                                                                                         player[i].targetanimation=sneakanim;
10517                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10518                                                                                                         player[i].targetframe=0;
10519                                                                                                 }
10520                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10521                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10522                                                                                                 }
10523                                                                                                 if(player[i].targetanimation==hanganim){
10524                                                                                                         player[i].currentanimation=jumpdownanim;
10525                                                                                                         player[i].targetanimation=jumpdownanim;
10526                                                                                                         player[i].target=0;
10527                                                                                                         player[i].currentframe=0;
10528                                                                                                         player[i].targetframe=1;
10529                                                                                                         player[i].velocity=0;
10530                                                                                                         player[i].velocity.y+=gravity;
10531                                                                                                         player[i].coords.y-=1.4;
10532                                                                                                         player[i].grabdelay=1;
10533                                                                                                 }
10534                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10535                                                                                                         player[i].targetrotation+=180;
10536                                                                                                 movekey=1;
10537                                                                                         }
10538                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10539                                                                                                 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)){
10540                                                                                                         player[i].jumpstart=0;
10541                                                                                                         player[i].targetanimation=jumpupanim;
10542                                                                                                         player[i].target=0;
10543                                                                                                         player[i].targetframe=0;
10544                                                                                                         player[i].rotation=player[i].targetrotation;
10545                                                                                                         player[i].transspeed=20;
10546                                                                                                         player[i].FootLand(0,1);
10547                                                                                                         player[i].FootLand(1,1);
10548
10549                                                                                                         facing=0;
10550                                                                                                         facing.z=-1;
10551                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10552
10553                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10554                                                                                                         if(!movekey)player[i].velocity=0;
10555
10556                                                                                                         //Dodge sweep?
10557                                                                                                         target=-2;
10558                                                                                                         if(numplayers>1)
10559                                                                                                                 for(j=0;j<numplayers;j++){
10560                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10561                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10562                                                                                                                                         if(target>=0)target=-1;
10563                                                                                                                                         else target=j;
10564                                                                                                                                 }
10565                                                                                                                         }
10566                                                                                                                 }
10567                                                                                                                 if(target>=0)player[i].velocity.y=1;
10568                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10569                                                                                                                         player[i].velocity.y=7;
10570                                                                                                                         player[i].crouchtogglekeydown=1;
10571                                                                                                                 }
10572                                                                                                                 else player[i].velocity.y=5;
10573
10574                                                                                                                 if(mousejump&&i==0&&debugmode){
10575                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10576                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10577                                                                                                                 }
10578
10579                                                                                                                 player[i].coords.y+=.2;
10580                                                                                                                 player[i].jumppower-=1;
10581
10582                                                                                                                 static float gLoc[3];
10583                                                                                                                 static float vel[3];
10584                                                                                                                 gLoc[0]=player[i].coords.x;
10585                                                                                                                 gLoc[1]=player[i].coords.y;
10586                                                                                                                 gLoc[2]=player[i].coords.z;
10587                                                                                                                 vel[0]=player[i].velocity.x;
10588                                                                                                                 vel[1]=player[i].velocity.y;
10589                                                                                                                 vel[2]=player[i].velocity.z;
10590
10591                                                                                                                 if(i==0){
10592                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
10593                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10594                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
10595                                                                                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
10596                                                                                                                 }
10597
10598                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
10599                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10600                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
10601                                                                                                                 FSOUND_SetPaused(channels[jumpsound], FALSE);
10602                                                                                                 }               
10603                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10604                                                                                                         player[i].targetanimation=player[i].getLanding();
10605                                                                                                         player[i].landhard=0;
10606                                                                                                         player[i].target=0;
10607                                                                                                         player[i].targetframe=2;
10608                                                                                                         player[i].jumpstart=1;
10609                                                                                                         player[i].tempdeltav=deltav;
10610                                                                                                 }               
10611                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10612                                                                                                         if(player[i].jumppower>multiplier*6){
10613                                                                                                                 player[i].velocity.y+=multiplier*6;
10614                                                                                                                 player[i].jumppower-=multiplier*6;
10615                                                                                                         }
10616                                                                                                         if(player[i].jumppower<=multiplier*6){
10617                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10618                                                                                                                 player[i].jumppower=0;
10619                                                                                                         }
10620                                                                                                 }
10621                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;           
10622                                                                                         }
10623
10624                                                                                         if(!movekey){
10625                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10626                                                                                                         player[i].targetanimation=player[i].getStop();
10627                                                                                                         player[i].target=0;
10628                                                                                                         player[i].targetframe=0;
10629                                                                                                 }
10630                                                                                                 if(player[i].targetanimation==sneakanim){
10631                                                                                                         player[i].targetanimation=player[i].getCrouch();
10632                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10633                                                                                                         player[i].targetframe=0;
10634                                                                                                 }
10635                                                                                         }
10636                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10637                                                                                                 player[i].targetanimation=player[i].getStop();
10638                                                                                                 player[i].target=0;
10639                                                                                                 player[i].targetframe=0;
10640                                                                                         }
10641                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10642                                                                                                 player[i].targetanimation=player[i].getStop();
10643                                                                                                 player[i].target=0;
10644                                                                                                 player[i].targetframe=0;
10645                                                                                         }
10646                                                                                 }
10647                                                                 }
10648                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10649                                                         }
10650
10651                                                         //Rotation
10652                                                         for(k=0;k<numplayers;k++){
10653                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10654                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10655                                                                         else player[k].rotation+=360;
10656                                                                 }
10657
10658                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10659                                                                         player[k].targetanimation=player[k].getStop();
10660                                                                         player[k].targetframe=0;
10661                                                                         player[k].target=0;
10662                                                                 }
10663
10664                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10665                                                                         player[k].targettilt=0;
10666                                                                 }
10667                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10668                                                                         player[k].targettilt=0;
10669                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10670                                                                         player[k].jumppower+=multiplier*7;
10671                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10672                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10673                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10674                                                                 }
10675
10676                                                                 if(player[k].isRun()){
10677                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10678                                                                 }
10679
10680                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10681                                                                 else if(player[k].tilt>player[k].targettilt){
10682                                                                         player[k].tilt-=multiplier*150;
10683                                                                 }
10684                                                                 else if(player[k].tilt<player[k].targettilt){
10685                                                                         player[k].tilt+=multiplier*150;
10686                                                                 }
10687
10688                                                                 player[k].grabdelay-=multiplier;
10689                                                         }
10690
10691                                                         for(k=0;k<numplayers;k++){
10692                                                                 player[k].DoAnimations();
10693                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10694                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10695                                                         }
10696
10697                                                         objects.DoStuff();
10698                                                         /*
10699                                                         player[0].righthandmorphstart=0;
10700                                                         player[0].righthandmorphend=1;
10701                                                         player[0].lefthandmorphstart=0;
10702                                                         player[0].lefthandmorphend=1;
10703                                                         player[0].headmorphstart=0;
10704                                                         player[0].headmorphend=2;*/
10705
10706                                                         /*
10707                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10708                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10709                                                         player[0].righthandmorphend=1;
10710                                                         player[0].targetrighthandmorphness=1;
10711
10712                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10713                                                         player[0].lefthandmorphend=0;
10714                                                         player[0].targetlefthandmorphness=1;
10715
10716                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10717                                                         player[0].headmorphend=2;
10718                                                         player[0].targetheadmorphness=1;
10719                                                         }
10720                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10721                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10722                                                         player[0].righthandmorphend=0;
10723                                                         player[0].targetrighthandmorphness=1;
10724
10725                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10726                                                         player[0].lefthandmorphend=1;
10727                                                         player[0].targetlefthandmorphness=1;
10728
10729                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10730                                                         player[0].headmorphend=0;
10731                                                         player[0].targetheadmorphness=1;
10732                                                         }
10733                                                         */
10734                                                         if(numenvsounds!=0)
10735                                                                 for(j=numenvsounds-1;j>=0;j--){
10736                                                                         envsoundlife[j]-=multiplier;
10737                                                                         if(envsoundlife[j]<0){
10738                                                                                 numenvsounds--;
10739                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10740                                                                                 envsound[j]=envsound[numenvsounds];
10741                                                                         }
10742                                                                 }
10743                                                                 if(!slomo)FSOUND_SetFrequency(FSOUND_ALL, 22050);
10744                                                                 if(slomo)FSOUND_SetFrequency(FSOUND_ALL, slomofreq);
10745
10746                                                                 if(tutoriallevel==1){
10747                                                                         XYZ temp;
10748                                                                         XYZ temp2;
10749                                                                         XYZ temp3;
10750                                                                         XYZ oldtemp;
10751                                                                         XYZ oldtemp2;
10752                                                                         temp.x=1011;
10753                                                                         temp.y=84;
10754                                                                         temp.z=491;
10755                                                                         temp2.x=1025;
10756                                                                         temp2.y=75;
10757                                                                         temp2.z=447;
10758                                                                         temp3.x=1038;
10759                                                                         temp3.y=76;
10760                                                                         temp3.z=453;
10761                                                                         oldtemp=temp;
10762                                                                         oldtemp2=temp2;
10763                                                                         if(tutorialstage>=51)
10764                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10765                                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
10766
10767                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10768                                                                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10769                                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
10770
10771                                                                                         gameon=0;
10772                                                                                         mainmenu=5;
10773
10774                                                                                         float gLoc[3]={0,0,0};
10775                                                                                         float vel[3]={0,0,0};
10776                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10777                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10778                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10779                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10780                                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10781                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10782
10783                                                                                         flashr=1;
10784                                                                                         flashg=0;
10785                                                                                         flashb=0;
10786                                                                                         flashamount=1;
10787                                                                                         flashdelay=1;
10788                                                                                 }
10789                                                                                 if(tutorialstage<51)
10790                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10791                                                                                                 float gLoc[3];
10792                                                                                                 float vel[3];
10793                                                                                                 gLoc[0]=player[0].coords.x;
10794                                                                                                 gLoc[1]=player[0].coords.y;
10795                                                                                                 gLoc[2]=player[0].coords.z;
10796                                                                                                 vel[0]=0;
10797                                                                                                 vel[1]=0;
10798                                                                                                 vel[2]=0;
10799                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10800                                                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10801                                                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
10802                                                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
10803
10804                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10805
10806                                                                                                 flashr=1;
10807                                                                                                 flashg=1;
10808                                                                                                 flashb=1;
10809                                                                                                 flashamount=1;
10810                                                                                                 flashdelay=1;
10811                                                                                         }
10812                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10813                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10814                                                                                                         float gLoc[3];
10815                                                                                                         float vel[3];
10816                                                                                                         gLoc[0]=player[1].coords.x;
10817                                                                                                         gLoc[1]=player[1].coords.y;
10818                                                                                                         gLoc[2]=player[1].coords.z;
10819                                                                                                         vel[0]=0;
10820                                                                                                         vel[1]=0;
10821                                                                                                         vel[2]=0;
10822                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10823                                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10824                                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10825                                                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10826
10827                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10828                                                                                                                 if(Random()%2==0){
10829                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10830                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10831                                                                                                                         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;
10832                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10833                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10834                                                                                                                 }
10835                                                                                                         }
10836
10837                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10838                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10839                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10840                                                                                                                 if(Random()%2==0){
10841                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10842                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10843                                                                                                                         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;
10844                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10845                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10846                                                                                                                 }
10847                                                                                                         }
10848                                                                                                 }
10849                                                                 }
10850
10851
10852                                                                 //3d sound
10853                                                                 static float gLoc[3];
10854                                                                 gLoc[0]=viewer.x;
10855                                                                 gLoc[1]=viewer.y;
10856                                                                 gLoc[2]=viewer.z;
10857                                                                 static float vel[3];
10858                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10859                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10860                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10861
10862                                                                 //Set orientation with forward and up vectors
10863                                                                 static XYZ upvector;
10864                                                                 upvector=0;
10865                                                                 upvector.z=-1;
10866
10867                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10868                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10869
10870                                                                 facing=0;
10871                                                                 facing.z=-1;
10872                                                                 
10873                                                                 facing=DoRotation(facing,-rotation2,0,0);
10874                                                                 facing=DoRotation(facing,0,0-rotation,0);
10875                 
10876                 
10877                                                                 static float ori[6];
10878                                                                 ori[0] = -facing.x;
10879                                                                 ori[1] = facing.y;
10880                                                                 ori[2] = -facing.z;
10881                                                                 ori[3] = -upvector.x;
10882                                                                 ori[4] = upvector.y;
10883                                                                 ori[5] = -upvector.z;
10884
10885                                                                 FSOUND_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10886                                                                 FSOUND_Update();
10887
10888                                                                 oldviewer=viewer;
10889                 }
10890         }
10891
10892         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10893                 Screenshot();
10894                 freezetogglekeydown=1;
10895         }
10896 }
10897
10898 void    Game::TickOnce(){
10899         //if(!console){
10900         if(!mainmenu)
10901                 if(directing||indialogue==-1){
10902                         rotation+=deltah*.7;
10903                         if(!invertmouse)rotation2+=deltav*.7;
10904                         if(invertmouse)rotation2-=deltav*.7;
10905                         if(rotation2>90)rotation2=90;
10906                         if(rotation2<-70)rotation2=-70;
10907                 }
10908                 if(mainmenu)rotation+=multiplier*5;
10909                 if(!mainmenu&&!indemo&&!registered){
10910                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
10911                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10912                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10913                         FSOUND_SetVolume(channels[stream_music3], 256);
10914
10915                         gameon=0;
10916                         mainmenu=12;
10917
10918                         float gLoc[3]={0,0,0};
10919                         float vel[3]={0,0,0};
10920                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10921                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10922                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10923                         FSOUND_SetVolume(channels[fireendsound], 256);
10924                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10925                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10926
10927                         flashr=1;
10928                         flashg=0;
10929                         flashb=0;
10930                         flashamount=1;
10931                         flashdelay=1;
10932                 }
10933
10934                 if(tryquit==1&&!registered&&mainmenu!=12){
10935                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
10936                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10937                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10938                         FSOUND_SetVolume(channels[stream_music3], 256);
10939
10940                         gameon=0;
10941                         mainmenu=12;
10942
10943                         float gLoc[3]={0,0,0};
10944                         float vel[3]={0,0,0};
10945                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10946                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10947                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10948                         FSOUND_SetVolume(channels[fireendsound], 256);
10949                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10950                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10951
10952                         flashr=1;
10953                         flashg=0;
10954                         flashb=0;
10955                         flashamount=1;
10956                         flashdelay=1;
10957                 }
10958                 //}
10959 }
10960
10961 void    Game::TickOnceAfter(){
10962         static XYZ colviewer;
10963         static XYZ coltarget;
10964         static XYZ target;
10965         static XYZ col;
10966         static float brotate;
10967         static XYZ facing;
10968         static int i,j;
10969         static float changedelay;
10970         static bool alldead;
10971         static float unseendelay;
10972         static float cameraspeed;
10973
10974         if(!mainmenu){
10975
10976                 if(environment==snowyenvironment)music1=stream_music1snow;
10977                 if(environment==grassyenvironment)music1=stream_music1grass;
10978                 if(environment==desertenvironment)music1=stream_music1desert;
10979
10980                 realthreat=0;
10981
10982                 musictype=music1;
10983                 for(i=0;i<numplayers;i++){
10984                         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)){
10985                                 musictype=stream_music2;
10986                                 realthreat=1;
10987                         }
10988                 }
10989                 if(player[0].dead)musictype=stream_music3;
10990
10991
10992                 if(musictype==stream_music2){
10993                         unseendelay=1;
10994                 }
10995
10996                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
10997                         unseendelay-=multiplier;
10998                         if(unseendelay>0){
10999                                 musictype=stream_music2;
11000                         }
11001                 }
11002
11003
11004                 if(loading==2){
11005                         musictype=stream_music3;
11006                         musicvolume[2]=512;
11007                         musicvolume[0]=0;
11008                         musicvolume[1]=0;
11009                         musicvolume[3]=0;
11010                 }       
11011
11012                 if(musictoggle){                        
11013                         if(musictype!=oldmusictype&&musictype==stream_music2){
11014                                 static float gLoc[3];
11015                                 static float vel[3];
11016                                 gLoc[0]=cameraloc.x;
11017                                 gLoc[1]=cameraloc.y;
11018                                 gLoc[2]=cameraloc.z;
11019                                 vel[0]=0;
11020                                 vel[1]=0;
11021                                 vel[2]=0;
11022                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, TRUE);
11023                                 FSOUND_SetVolume(channels[alarmsound], 512);
11024                                 FSOUND_SetPaused(channels[alarmsound], FALSE);
11025
11026                         }
11027                 }
11028                 musicselected=musictype;
11029
11030                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
11031                 else musicvolume[0]-=multiplier*450;
11032                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
11033                 else musicvolume[1]-=multiplier*450;
11034                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
11035                 else musicvolume[2]-=multiplier*450;
11036                 /*
11037                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
11038                 else musicvolume[0]-=multiplier*450;
11039                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
11040                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
11041                 else musicvolume[1]-=multiplier*100;
11042                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
11043                 else musicvolume[2]-=multiplier*450;*/
11044
11045                 for(i=0;i<3;i++){
11046                         if(musicvolume[i]<0)musicvolume[i]=0;
11047                         if(musicvolume[i]>512)musicvolume[i]=512;
11048                 }
11049
11050                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
11051
11052                 if(musictoggle){                
11053                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
11054                                 PlayStreamEx( music1, strm[music1], NULL, TRUE);
11055                                 FSOUND_SetPaused(channels[music1], FALSE);
11056                         }
11057                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
11058                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, TRUE);
11059                                 FSOUND_SetPaused(channels[stream_music2], FALSE);
11060                         }
11061                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
11062                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11063                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
11064                         }
11065                 }
11066
11067                 if(!musictoggle){               
11068                         FSOUND_SetPaused(channels[music1], TRUE);
11069                         FSOUND_SetPaused(channels[stream_music2], TRUE);
11070                         FSOUND_SetPaused(channels[stream_music3], TRUE);
11071
11072                         for(i=0;i<4;i++){
11073                                 oldmusicvolume[i]=0;
11074                                 musicvolume[i]=0;
11075                         }
11076                 }
11077
11078                 if(musictoggle){                
11079                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
11080                                 FSOUND_SetPaused(channels[music1], TRUE);
11081                         }
11082                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
11083                                 FSOUND_SetPaused(channels[stream_music2], TRUE);
11084                         }
11085                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
11086                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
11087                         }
11088
11089                         if(musicvolume[0]!=oldmusicvolume[0]){
11090                                 FSOUND_SetVolume(channels[music1], musicvolume[0]);
11091                         }
11092                         if(musicvolume[1]!=oldmusicvolume[1]){
11093                                 FSOUND_SetVolume(channels[stream_music2], musicvolume[1]);
11094                         }
11095                         if(musicvolume[2]!=oldmusicvolume[2]){
11096                                 FSOUND_SetVolume(channels[stream_music3], musicvolume[2]);
11097                         }
11098
11099                         for(i=0;i<3;i++){
11100                                 oldmusicvolume[i]=musicvolume[i];
11101                         }
11102                 }
11103
11104                 killhotspot=2;
11105                 if(numhotspots)
11106                         for(i=0;i<numhotspots;i++){
11107                                 if(hotspottype[i]>10&&hotspottype[i]<20){
11108                                         if(player[hotspottype[i]-10].dead==0){
11109                                                 killhotspot=0;
11110                                         }
11111                                         else if(killhotspot==2)
11112                                                 killhotspot=1;
11113                                 }
11114                         }
11115                         if(killhotspot==2)killhotspot=0;
11116
11117
11118                         winhotspot=0;
11119                         if(numhotspots)
11120                                 for(i=0;i<numhotspots;i++){
11121                                         if(hotspottype[i]==-1){
11122                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
11123                                                         winhotspot=1;
11124                                         }
11125                                 }
11126
11127                                 int numalarmed=0;
11128                                 if(numplayers>1)
11129                                         for(i=1;i<numplayers;i++){              
11130                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
11131                                         }
11132                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
11133
11134                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){          
11135                                                 if(player[0].dead&&changedelay<=0){
11136                                                         changedelay=1;
11137                                                         targetlevel=whichlevel;
11138                                                 }
11139                                                 alldead=1;
11140                                                 if(numplayers>1)
11141                                                         for(i=1;i<numplayers;i++){              
11142                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
11143                                                         }
11144
11145
11146                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
11147                                                                 changedelay=1;
11148                                                                 targetlevel=whichlevel+1;
11149                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11150                                                         }
11151                                                         if(winhotspot||windialogue){
11152                                                                 changedelay=0.1;
11153                                                                 targetlevel=whichlevel+1;
11154                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11155                                                         }
11156
11157
11158                                                         if(killhotspot){
11159                                                                 changedelay=1;
11160                                                                 targetlevel=whichlevel+1;
11161                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11162                                                         }
11163
11164                                                         if(changedelay>0&&!player[0].dead&&!won){
11165                                                                 //high scores, awards, win
11166                                                                 if(campaign){
11167                                                                         won=1;
11168                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11169                                                                         accountcampaignchoicesmade[accountactive]++;
11170                                                                         accountcampaignscore[accountactive]+=bonustotal;
11171                                                                         scoreadded=1;
11172                                                                         accountcampaigntime[accountactive]+=leveltime;
11173                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
11174
11175                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11176                                                                 }
11177                                                                 else
11178                                                                 {
11179                                                                         won=1;
11180                                                                         if(!debugmode){
11181                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
11182                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;            
11183                                                                         }
11184                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11185
11186                                                                 }
11187                                                         }
11188                                         }
11189
11190                                         if(!winfreeze){
11191
11192                                                 if(leveltime<1){
11193                                                         loading=0;
11194                                                         changedelay=.1;
11195                                                         alldead=0;
11196                                                         winhotspot=0;
11197                                                         killhotspot=0;
11198                                                 }
11199
11200                                                 if(!editorenabled&&gameon&&!mainmenu){
11201                                                         if(changedelay!=-999)changedelay-=multiplier/7;
11202                                                         if(player[0].dead)targetlevel=whichlevel;
11203                                                         if(loading==2&&!campaign){
11204                                                                 flashr=1;
11205                                                                 flashg=0;
11206                                                                 flashb=0;
11207                                                                 flashamount=1;
11208                                                                 flashdelay=1;
11209                                                                 loadtime=0;
11210
11211                                                                 float gLoc[3]={0,0,0};
11212                                                                 float vel[3]={0,0,0};
11213                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11214                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11215                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11216                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11217                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
11218                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11219
11220                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
11221                                                                         startbonustotal=bonustotal;
11222                                                                 }
11223                                                                 if(!player[0].dead)Loadlevel(targetlevel);
11224                                                                 if(player[0].dead)Loadlevel(whichlevel);
11225
11226                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11227                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11228                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11229                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11230                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
11231                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11232
11233                                                                 loading=3;
11234                                                         }
11235                                                         if(loading==2&&targetlevel==whichlevel){
11236                                                                 flashr=1;
11237                                                                 flashg=0;
11238                                                                 flashb=0;
11239                                                                 flashamount=1;
11240                                                                 flashdelay=1;
11241                                                                 loadtime=0;
11242
11243                                                                 float gLoc[3]={0,0,0};
11244                                                                 float vel[3]={0,0,0};
11245                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11246                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11247                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11248                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11249                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
11250                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11251
11252                                                                 for(i=0;i<255;i++){
11253                                                                         mapname[i]='\0';
11254                                                                 }
11255                                                                 mapname[0]=':';
11256                                                                 mapname[1]='D';
11257                                                                 mapname[2]='a';
11258                                                                 mapname[3]='t';
11259                                                                 mapname[4]='a';
11260                                                                 mapname[5]=':';
11261                                                                 mapname[6]='M';
11262                                                                 mapname[7]='a';
11263                                                                 mapname[8]='p';
11264                                                                 mapname[9]='s';
11265                                                                 mapname[10]=':';
11266                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
11267                                                                 Loadlevel(mapname);
11268
11269                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11270                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11271                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11272                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11273                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
11274                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11275
11276                                                                 loading=3;
11277                                                         }
11278                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
11279                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
11280                                                                 if(accountprogress[accountactive]>3&&!registered){
11281                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
11282                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11283                                                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
11284                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
11285
11286                                                                         gameon=0;
11287                                                                         mainmenu=12;
11288                                                                         accountprogress[accountactive]=3;
11289
11290                                                                         float gLoc[3]={0,0,0};
11291                                                                         float vel[3]={0,0,0};
11292                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11293                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11294                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11295                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
11296                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
11297                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11298
11299                                                                         flashr=1;
11300                                                                         flashg=0;
11301                                                                         flashb=0;
11302                                                                         flashamount=1;
11303                                                                         flashdelay=1;
11304                                                                 }
11305                                                                 else{
11306                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
11307                                                                                 winfreeze=1;
11308                                                                                 changedelay=-999;
11309                                                                         }
11310                                                                         if(player[0].dead)loading=1;
11311                                                                 }
11312                                                         }
11313                                                 }
11314
11315                                                 if(campaign)
11316                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11317                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11318                                                                         endgame=1;
11319                                                                 }
11320                                                         }
11321                                                         else if(mainmenu==0&&winfreeze){
11322                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11323                                                                         stealthloading=1;
11324                                                                 else stealthloading=0;
11325
11326                                                                 if(!stealthloading){
11327                                                                         float gLoc[3]={0,0,0};
11328                                                                         float vel[3]={0,0,0};
11329                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11330                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11331                                                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11332                                                                         FSOUND_SetVolume(channels[firestartsound], 256);
11333                                                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
11334                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11335
11336                                                                         flashr=1;
11337                                                                         flashg=0;
11338                                                                         flashb=0;
11339                                                                         flashamount=1;
11340                                                                         flashdelay=1;
11341                                                                 }
11342
11343                                                                 startbonustotal=0;
11344
11345                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
11346                                                                 //campaignnumlevels=0;
11347                                                                 //accountcampaignchoicesmade[accountactive]=0;
11348                                                                 ipstream.ignore(256,':');
11349                                                                 ipstream >> campaignnumlevels;
11350                                                                 for(i=0;i<campaignnumlevels;i++){
11351                                                                         ipstream.ignore(256,':');
11352                                                                         ipstream.ignore(256,':');
11353                                                                         ipstream.ignore(256,' ');
11354                                                                         ipstream >> campaignmapname[i];
11355                                                                         ipstream.ignore(256,':');
11356                                                                         ipstream >> campaigndescription[i];
11357                                                                         for(j=0;j<256;j++){
11358                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11359                                                                         }
11360                                                                         ipstream.ignore(256,':');
11361                                                                         ipstream >> campaignchoosenext[i];
11362                                                                         ipstream.ignore(256,':');
11363                                                                         ipstream >> campaignnumnext[i];
11364                                                                         if(campaignnumnext[i])
11365                                                                                 for(j=0;j<campaignnumnext[i];j++){
11366                                                                                         ipstream.ignore(256,':');
11367                                                                                         ipstream >> campaignnextlevel[i][j];
11368                                                                                         campaignnextlevel[i][j]-=1;
11369                                                                                 }
11370                                                                                 ipstream.ignore(256,':');
11371                                                                                 ipstream >> campaignlocationx[i];
11372                                                                                 ipstream.ignore(256,':');
11373                                                                                 ipstream >> campaignlocationy[i];
11374                                                                 }
11375                                                                 ipstream.close();
11376
11377                                                                 for(i=0;i<campaignnumlevels;i++){
11378                                                                         levelvisible[i]=0;
11379                                                                         levelhighlight[i]=0;
11380                                                                 }
11381
11382
11383                                                                 for(i=0;i<campaignnumlevels;i++){
11384                                                                         levelvisible[i]=0;
11385                                                                         levelhighlight[i]=0;
11386                                                                 }
11387
11388                                                                 levelorder[0]=0;
11389                                                                 levelvisible[0]=1;
11390                                                                 if(accountcampaignchoicesmade[accountactive])
11391                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11392                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11393                                                                                 levelvisible[levelorder[i+1]]=1;
11394                                                                         }
11395                                                                         int whichlevelstart;
11396                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11397                                                                         if(whichlevelstart<0){
11398                                                                                 campaignchoicenum=1;
11399                                                                                 campaignchoicewhich[0]=0;
11400                                                                         }
11401                                                                         else
11402                                                                         {
11403                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11404                                                                                 if(campaignchoicenum)
11405                                                                                         for(i=0;i<campaignchoicenum;i++){
11406                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11407                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11408                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11409                                                                                         }
11410                                                                         }
11411
11412                                                                         loading=2;
11413                                                                         loadtime=0;
11414                                                                         targetlevel=7;
11415                                                                         //if(firstload)TickOnceAfter();
11416                                                                         if(!firstload)LoadStuff();
11417                                                                         //else {
11418                                                                         for(i=0;i<255;i++){
11419                                                                                 mapname[i]='\0';
11420                                                                         }
11421                                                                         mapname[0]=':';
11422                                                                         mapname[1]='D';
11423                                                                         mapname[2]='a';
11424                                                                         mapname[3]='t';
11425                                                                         mapname[4]='a';
11426                                                                         mapname[5]=':';
11427                                                                         mapname[6]='M';
11428                                                                         mapname[7]='a';
11429                                                                         mapname[8]='p';
11430                                                                         mapname[9]='s';
11431                                                                         mapname[10]=':';
11432
11433                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11434                                                                         //accountcampaignchoicesmade[accountactive]++;
11435
11436
11437                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11438                                                                         whichchoice=0;
11439                                                                         visibleloading=1;
11440                                                                         stillloading=1;
11441                                                                         Loadlevel(mapname);
11442                                                                         campaign=1;
11443                                                                         mainmenu=0;
11444                                                                         gameon=1;
11445                                                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
11446
11447                                                                         stealthloading=0;
11448                                                         }
11449
11450                                                         if(loading==3)loading=0;
11451
11452                                         }
11453
11454                                         oldmusictype=musictype;
11455         }
11456
11457         facing=0;
11458         facing.z=-1;
11459
11460         facing=DoRotation(facing,-rotation2,0,0);
11461         facing=DoRotation(facing,0,0-rotation,0);
11462         viewerfacing=facing;
11463
11464         brotate=0;
11465         if(!cameramode){
11466                 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;
11467                 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;
11468                 target.y+=.1;
11469                 if(player[0].skeleton.free){
11470                         for(i=0;i<player[0].skeleton.num_joints;i++){
11471                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)                         
11472                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11473                         }
11474                         target.y+=.1;
11475                 }
11476                 if(player[0].skeleton.free!=2&&!autocam){
11477                         cameraspeed=20;
11478                         if(findLengthfast(&player[0].velocity)>400){
11479                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11480                         }
11481                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11482                         coltarget=target-cameraloc;
11483                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11484                         else {
11485                                 Normalise(&coltarget);
11486                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11487                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11488                         }
11489                         if(editorenabled)cameraloc=target;
11490                         cameradist+=multiplier*5;
11491                         if(cameradist>2.3)cameradist=2.3;
11492                         viewer=cameraloc-facing*cameradist;
11493                         colviewer=viewer;
11494                         coltarget=cameraloc;
11495                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11496                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11497                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11498                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11499                                         colviewer=viewer;
11500                                         coltarget=cameraloc;
11501                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;     
11502                                 }
11503                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11504                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11505                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11506                                                 colviewer=viewer;
11507                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11508                                                         viewer=colviewer;
11509                                                 }
11510                                         }
11511                                         cameradist=findDistance(&viewer,&target);
11512                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11513                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11514                                         }
11515                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11516                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11517                                         }
11518                 }
11519                 if(player[0].skeleton.free!=2&&autocam){
11520                         cameraspeed=20;
11521                         if(findLengthfast(&player[0].velocity)>400){
11522                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11523                         }
11524                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11525                         cameradist+=multiplier*5;
11526                         if(cameradist>3.3)cameradist=3.3;
11527                         coltarget=target-cameraloc;
11528                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11529                         else if(findLengthfast(&coltarget)>1)
11530                         {
11531                                 Normalise(&coltarget);
11532                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11533                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11534                         }
11535                         if(editorenabled)cameraloc=target;
11536                         viewer=cameraloc;
11537                         colviewer=viewer;
11538                         coltarget=cameraloc;
11539                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11540                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11541                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11542                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11543                                         colviewer=viewer;
11544                                         coltarget=cameraloc;
11545                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;     
11546                                 }
11547                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11548                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11549                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11550                                                 colviewer=viewer;
11551                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11552                                                         viewer=colviewer;
11553                                                 }
11554                                         }
11555                                         cameradist=findDistance(&viewer,&target);
11556                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11557                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11558                                         }
11559                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11560                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11561                                         }
11562                 }
11563                 if(camerashake>.8)camerashake=.8;
11564                 //if(woozy>10)woozy=10;
11565                 //woozy+=multiplier;
11566                 woozy+=multiplier;
11567                 if(player[0].dead)camerashake=0;
11568                 if(player[0].dead)woozy=0;
11569                 camerashake-=multiplier*2;
11570                 blackout-=multiplier*2;
11571                 //if(player[0].isCrouch())woozy-=multiplier*8;
11572                 if(camerashake<0)camerashake=0;
11573                 if(blackout<0)blackout=0;
11574                 //if(woozy<0)woozy=0;
11575                 if(camerashake){
11576                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11577                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11578                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11579                 }
11580         }
11581 }