]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
Hack around crash on shutdown.
[lugaru.git] / Source / GameTick.cpp
1 #if PLATFORM_UNIX
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #else
6 #include <direct.h>
7 #endif
8
9 #include <ctime>
10 #include "Game.h"
11
12 using namespace std;
13
14 extern float multiplier;
15 extern XYZ viewer;
16 extern int environment;
17 extern float texscale;
18 extern Terrain terrain;
19 extern FSOUND_SAMPLE    *samp[100];
20 extern int channels[100];
21 extern Sprites sprites;
22 extern int kTextureSize;
23 extern float screenwidth,screenheight;
24 extern float gravity;
25 extern int detail;
26 extern float texdetail;
27 extern Objects objects;
28 extern int slomo;
29 extern float slomodelay;
30 extern bool floatjump;
31 extern float volume;
32 extern Animation animation[animation_count];
33 extern Light light;
34 extern float texdetail;
35 extern GLubyte bloodText[512*512*3];
36 extern GLubyte wolfbloodText[512*512*3];
37 extern float terraindetail;
38 extern float camerashake;
39 extern float woozy;
40 extern float blackout;
41 extern bool cellophane;
42 extern bool musictoggle;
43 extern int difficulty;
44 extern Weapons weapons;
45 extern Person player[maxplayers];
46 extern int numplayers;
47 extern int bloodtoggle;
48 extern bool invertmouse;
49 extern float windvar;
50 extern float precipdelay;
51 extern XYZ viewerfacing;
52 extern bool ambientsound;
53 extern bool mousejump;
54 extern float viewdistance;
55 extern bool freeze;
56 extern bool autoslomo;
57 extern int newnetmessages;
58 extern char netmessages[256];
59 extern bool keyboardfrozen;
60 extern int netdatanew;
61 extern bool loadingstuff;
62 extern char mapname[256];
63 extern XYZ windvector;
64 extern bool buttons[3];
65 extern bool debugmode;
66 static int music1;
67 extern int mainmenu;
68 extern int oldmainmenu;
69 extern bool visibleloading;
70 extern int loadscreencolor;
71 extern float flashamount,flashr,flashg,flashb;
72 extern int flashdelay;
73 extern XYZ envsound[30];
74 extern float envsoundvol[30];
75 extern int numenvsounds;
76 extern float envsoundlife[30];
77 extern float usermousesensitivity;
78 extern bool ismotionblur;
79 extern bool foliage;
80 extern bool trilinear;
81 extern bool damageeffects;
82 extern bool showpoints;
83 extern bool texttoggle;
84 extern bool alwaysblur;
85 extern float gamespeed;
86 extern bool decals;
87 extern bool vblsync;
88 extern bool immediate;
89 extern bool velocityblur;
90 extern int bonus;
91 extern int oldbonus;
92 extern float bonusvalue;
93 extern float bonustotal;
94 extern float bonustime;
95 extern float startbonustotal;
96 extern float tintr,tintg,tintb;
97 extern float bonusnum[100];
98 extern bool skyboxtexture;
99 extern float skyboxr;
100 extern float skyboxg;
101 extern float skyboxb;
102 extern float skyboxlightr;
103 extern float skyboxlightg;
104 extern float skyboxlightb;
105 extern float fadestart;
106 extern float slomospeed;
107 extern float slomofreq;
108 extern int tutoriallevel;
109 extern float smoketex;
110 extern float tutorialstagetime;
111 extern int tutorialstage;
112 extern float tutorialmaxtime;
113 extern float tutorialsuccess;
114 extern bool againbonus;
115 extern bool reversaltrain;
116 extern bool canattack;
117 extern bool cananger;
118 extern float damagedealt;
119 extern float damagetaken;
120 extern int maptype;
121 extern int editoractive;
122 extern int editorpathtype;
123 extern bool oldbuttons[3];
124
125 extern float hostiletime;
126
127 extern bool gamestarted;
128
129 extern int numhotspots;
130 extern int winhotspot;
131 extern int windialogue;
132 extern int killhotspot;
133 extern XYZ hotspot[40];
134 extern int hotspottype[40];
135 extern float hotspotsize[40];
136 extern char hotspottext[40][256];
137 extern int currenthotspot;
138
139 extern int kBitsPerPixel;
140 extern int hostile;
141
142 extern int numaccounts;
143 extern int accountactive;
144 extern int accountdifficulty[10];
145 extern int accountprogress[10];
146 extern float accountpoints[10];
147 extern float accounthighscore[10][50];
148 extern float accountfasttime[10][50];
149 extern bool accountunlocked[10][60];
150 extern char accountname[10][256];
151
152 extern bool stillloading;
153 extern bool winfreeze;
154
155 extern int numfalls;
156 extern int numflipfail;
157 extern int numseen;
158 extern int numstaffattack;
159 extern int numswordattack;
160 extern int numknifeattack;
161 extern int numunarmedattack;
162 extern int numescaped;
163 extern int numflipped;
164 extern int numwallflipped;
165 extern int numthrowkill;
166 extern int numafterkill;
167 extern int numreversals;
168 extern int numattacks;
169 extern int maxalarmed;
170 extern int numresponded;
171
172 extern int numdialogues;
173 extern int numdialogueboxes[max_dialogues];
174 extern int dialoguetype[max_dialogues];
175 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
176 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
177 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
178 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
179 extern char dialoguename[max_dialogues][max_dialoguelength][64];
180 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
181 extern XYZ participantlocation[max_dialogues][10];
182 extern int participantfocus[max_dialogues][max_dialoguelength];
183 extern int participantaction[max_dialogues][max_dialoguelength];
184 extern float participantrotation[max_dialogues][10];
185 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
186 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
187 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
188 extern int indialogue;
189 extern int whichdialogue;
190 extern int directing;
191 extern float dialoguetime;
192 extern int dialoguegonethrough[20];
193
194 extern bool campaign;
195
196 extern float oldgamespeed;
197
198 extern float accountcampaignhighscore[10];
199 extern float accountcampaignfasttime[10];
200 extern float accountcampaignscore[10];
201 extern float accountcampaigntime[10];
202
203 extern int accountcampaignchoicesmade[10];
204 extern int accountcampaignchoices[10][5000];
205 /********************> Tick() <*****/
206 extern FSOUND_STREAM * strm[20];
207 extern "C"      void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
208 extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
209
210 extern void ScreenShot(const char * fname);
211 void Screenshot (void)
212 {
213         char temp[1024];
214         time_t  t = time(NULL);
215         struct  tm *tme = localtime(&t);
216         sprintf(temp, "Screenshots\\Screenshot_%04d_%02d_%02d--%02d_%02d_%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
217
218         mkdir("Screenshots", S_IRWXU);
219         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
220
221         /*FSSpec                                MAC_file;
222         GraphicsExportComponent         QT_exporter;
223         OSErr                           MAC_error_code;
224         CGrafPtr                        MAC_currentPort;
225         GDHandle                        MAC_currentDevice;
226         unsigned char*          MAC_pixels;
227         Rect                            MAC_picture_rectangle;
228         GWorldPtr                       MAC_offscreen_graphics_port;
229
230         static int numscreenshots=0;
231
232         // Make an FSSpec
233         static char buf[256];
234         if(numscreenshots==0){
235         buf[0]=26;
236         buf[1]=':';
237         buf[2]='S';
238         buf[3]='c';
239         buf[4]='r';
240         buf[5]='e';
241         buf[6]='e';
242         buf[7]='n';
243         buf[8]='s';
244         buf[9]='h';
245         buf[10]='o';
246         buf[11]='t';
247         buf[12]='s';
248         buf[13]=':';
249         buf[14]='S';
250         buf[15]='c';
251         buf[16]='r';
252         buf[17]='e';
253         buf[18]='e';
254         buf[19]='n';
255         buf[20]='s';
256         buf[21]='h';
257         buf[22]='o';
258         buf[23]='t';
259         buf[24]='0';
260         buf[25]='0';
261         buf[26]='0';
262         }
263
264         FInfo *fndrInfo;
265         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
266         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
267         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
268         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
269         numscreenshots++;
270         buf[26]++;
271         if(buf[26]==':'){
272         buf[26]='0';
273         buf[25]++;
274         if(buf[25]==':'){
275         buf[25]='0';
276         buf[24]++;
277         if(buf[24]==':'){
278         buf[24]='9';
279         buf[25]='9';
280         buf[26]='9';
281         }
282         }
283         }
284         }
285         }
286
287
288         // Get the GWorld
289         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
290         //assert(MAC_gWorld != NULL);
291
292         // Allocate memory for loading image
293         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
294         if (MAC_pixels == NULL) {
295         //UTIL_Error("Could not create Texture data.");
296         return;
297         }
298
299         // Get GWorld
300         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);      
301
302         // Make a picture Rectangle
303         MAC_picture_rectangle.left = 0;
304         MAC_picture_rectangle.right = screenwidth;
305         MAC_picture_rectangle.top = 0;
306         MAC_picture_rectangle.bottom = screenheight;    
307
308         // Create new offscreen GWorld
309         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
310         if (MAC_error_code)     {
311         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
312         delete MAC_pixels;
313         //UTIL_Error("Could not create offscreen GWorld. ");
314         return;
315
316         }
317
318         // Copy OpenGL Context to new GWorld
319         glReadBuffer(GL_FRONT); 
320         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
321
322         // Swizzle texture
323         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
324         unsigned char temp = MAC_pixels[byte+0];
325         MAC_pixels[byte+0] = MAC_pixels[byte+3];
326         MAC_pixels[byte+3] = MAC_pixels[byte+2];
327         MAC_pixels[byte+2] = MAC_pixels[byte+1];
328         MAC_pixels[byte+1] = temp;
329         }
330
331         // Flip the image  :(   This could probably be optimized
332         int vert;
333         int src_index;
334         int dst_index;
335         unsigned char temp;
336         for (int horz = 0; horz < screenwidth; ++horz)
337         for (vert = 0; vert < screenheight / 2; ++vert) {               
338         src_index = (screenwidth * vert + horz) * 4;
339         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
340
341         temp=MAC_pixels[src_index+0];
342         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
343         MAC_pixels[dst_index+0]=temp;
344
345         temp=MAC_pixels[src_index+1];
346         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
347         MAC_pixels[dst_index+1]=temp;
348
349         temp=MAC_pixels[src_index+2];
350         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
351         MAC_pixels[dst_index+2]=temp;
352
353         temp=MAC_pixels[src_index+3];
354         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
355         MAC_pixels[dst_index+3]=temp;
356         }
357
358
359
360         // Export the Gworld
361         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
362         if (MAC_error_code) {
363         //UTIL_Warning("Unable to export screenshot."); 
364         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
365         ::DisposeGWorld(MAC_offscreen_graphics_port);
366         delete MAC_pixels;
367         return;
368         }                                                                                               
369
370         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
371         if (MAC_error_code) {
372         ::CloseComponent(QT_exporter);
373         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
374         ::DisposeGWorld(MAC_offscreen_graphics_port);
375         delete MAC_pixels;
376         //UTIL_Warning("Unable to export screenshot.");
377         return;
378         }                                                               
379
380         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
381         if (MAC_error_code) {
382         ::CloseComponent(QT_exporter);
383         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
384         ::DisposeGWorld(MAC_offscreen_graphics_port);
385         delete MAC_pixels;
386         //UTIL_Warning("Unable to export screenshot.");
387         return;
388         }                                                       
389
390         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
391         if (MAC_error_code) {
392         ::CloseComponent(QT_exporter);
393         ::SetGWorld(MAC_currentPort, MAC_currentDevice);                        
394         ::DisposeGWorld(MAC_offscreen_graphics_port);
395         delete MAC_pixels;
396         //UTIL_Warning("Unable to export screenshot.");
397         return;
398         }                                               
399
400         ::CloseComponent(QT_exporter);
401         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
402         ::DisposeGWorld(MAC_offscreen_graphics_port);
403
404         delete MAC_pixels;*/
405 }
406
407
408
409 void    Game::SetUpLighting(){
410         if(environment==snowyenvironment){
411                 light.color[0]=.65;
412                 light.color[1]=.65;
413                 light.color[2]=.7;
414                 light.ambient[0]=.4;
415                 light.ambient[1]=.4;
416                 light.ambient[2]=.44;           
417         }
418         if(environment==desertenvironment){
419                 light.color[0]=.95;
420                 light.color[1]=.95;
421                 light.color[2]=.95;
422                 light.ambient[0]=.4;
423                 light.ambient[1]=.35;
424                 light.ambient[2]=.3;            
425         }
426
427         if(environment==grassyenvironment){
428                 light.color[0]=.95;
429                 light.color[1]=.95;
430                 light.color[2]=1;
431                 light.ambient[0]=.4;
432                 light.ambient[1]=.4;
433                 light.ambient[2]=.44;           
434         }
435         if(!skyboxtexture){
436                 light.color[0]=1;
437                 light.color[1]=1;
438                 light.color[2]=1;
439                 light.ambient[0]=.4;
440                 light.ambient[1]=.4;
441                 light.ambient[2]=.4;    
442         }
443         float average;
444         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
445         light.color[0]*=(skyboxlightr+average)/2;
446         light.color[1]*=(skyboxlightg+average)/2;
447         light.color[2]*=(skyboxlightb+average)/2;
448         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
449         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
450         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;   
451         /*
452         light.ambient[0]=0;
453         light.ambient[1]=0;
454         light.ambient[2]=0;     */
455 }
456
457 int Game::findPathDist(int start,int end){
458         int i,j,k,smallestcount,count,connected;
459         int last,last2,last3,last4;
460         int closest;
461
462         smallestcount=1000;
463         for(i=0;i<50;i++){
464                 count=0;
465                 last=start;
466                 last2=-1;
467                 last3=-1;
468                 last4=-1;
469                 while(last!=end&&count<30){
470                         closest=-1;
471                         for(j=0;j<numpathpoints;j++){
472                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
473                                 {
474                                         connected=0;
475                                         if(numpathpointconnect[j])
476                                                 for(k=0;k<numpathpointconnect[j];k++){
477                                                         if(pathpointconnect[j][k]==last)connected=1;
478                                                 }
479                                                 if(!connected)
480                                                         if(numpathpointconnect[last])
481                                                                 for(k=0;k<numpathpointconnect[last];k++){
482                                                                         if(pathpointconnect[last][k]==j)connected=1;
483                                                                 }
484                                                                 if(connected)
485                                                                         if(closest==-1||Random()%2==0){
486                                                                                 closest=j;
487                                                                         }
488                                 }
489                         }
490                         last4=last3;
491                         last3=last2;
492                         last2=last;
493                         last=closest;
494                         count++;
495                 }
496                 if(count<smallestcount)smallestcount=count;
497         }
498         return smallestcount;
499 }
500
501 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
502         static XYZ colpoint,colviewer,coltarget;
503         static float minx,minz,maxx,maxz,miny,maxy;
504         static int i;
505
506         //startpoint.y+=.7;
507         //endpoint.y+=.7;
508         //startpoint.y-=.1;
509         //endpoint.y-=.1;
510
511         minx=startpoint.x;
512         if(minx>endpoint.x)minx=endpoint.x;
513         miny=startpoint.y;
514         if(miny>endpoint.y)miny=endpoint.y;
515         minz=startpoint.z;
516         if(minz>endpoint.z)minz=endpoint.z;
517
518         maxx=startpoint.x;
519         if(maxx<endpoint.x)maxx=endpoint.x;
520         maxy=startpoint.y;
521         if(maxy<endpoint.y)maxy=endpoint.y;
522         maxz=startpoint.z;
523         if(maxz<endpoint.z)maxz=endpoint.z;
524
525         minx-=1;
526         miny-=1;
527         minz-=1;
528         maxx+=1;
529         maxy+=1;
530         maxz+=1;
531
532         for(i=0;i<objects.numobjects;i++){
533                 if(objects.position[i].x>minx-objects.model[i].boundingsphereradius&&objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&objects.position[i].y>miny-objects.model[i].boundingsphereradius&&objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&objects.position[i].z>minz-objects.model[i].boundingsphereradius&&objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
534                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
535                                 colviewer=startpoint;
536                                 coltarget=endpoint;
537                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;  
538                         }
539                 }
540         }
541
542         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
543
544         return -1;
545 }
546
547 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
548         static XYZ colpoint,colviewer,coltarget;
549         static float minx,minz,maxx,maxz,miny,maxy;
550         static int i;
551
552         //startpoint.y+=.7;
553         //endpoint.y+=.7;
554         //startpoint.y-=.1;
555         //endpoint.y-=.1;
556
557         minx=startpoint.x;
558         if(minx>endpoint.x)minx=endpoint.x;
559         miny=startpoint.y;
560         if(miny>endpoint.y)miny=endpoint.y;
561         minz=startpoint.z;
562         if(minz>endpoint.z)minz=endpoint.z;
563
564         maxx=startpoint.x;
565         if(maxx<endpoint.x)maxx=endpoint.x;
566         maxy=startpoint.y;
567         if(maxy<endpoint.y)maxy=endpoint.y;
568         maxz=startpoint.z;
569         if(maxz<endpoint.z)maxz=endpoint.z;
570
571         minx-=1;
572         miny-=1;
573         minz-=1;
574         maxx+=1;
575         maxy+=1;
576         maxz+=1;
577
578         if(what!=1000){
579                 if(objects.position[what].x>minx-objects.model[what].boundingsphereradius&&objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&objects.position[what].y>miny-objects.model[what].boundingsphereradius&&objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&objects.position[what].z>minz-objects.model[what].boundingsphereradius&&objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
580                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
581                                 colviewer=startpoint;
582                                 coltarget=endpoint;
583                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i; 
584                         }
585                 }
586         }
587
588         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
589
590         return -1;
591 }
592
593 void    Game::Setenvironment(int which)
594 {
595         LOGFUNC;
596
597         LOG(" Setting environment...");
598
599         float temptexdetail;
600         environment=which;
601 /*
602         FSOUND_SetPaused(channels[music1snow], TRUE);
603         FSOUND_SetPaused(channels[music1grass], TRUE);
604         FSOUND_SetPaused(channels[music1desert], TRUE);
605         FSOUND_SetPaused(channels[wind], TRUE);
606         FSOUND_SetPaused(channels[desertambient], TRUE);
607 */
608         FSOUND_SetPaused(channels[stream_music1snow], TRUE);
609         FSOUND_SetPaused(channels[stream_music1grass], TRUE);
610         FSOUND_SetPaused(channels[stream_music1desert], TRUE);
611         FSOUND_SetPaused(channels[stream_wind], TRUE);
612         FSOUND_SetPaused(channels[stream_desertambient], TRUE);
613
614
615         if(environment==snowyenvironment){
616                 windvector=0;
617                 windvector.z=3;
618                 if(ambientsound){
619                         //PlaySoundEx( wind, samp[wind], NULL, TRUE);
620                         PlayStreamEx(stream_wind, strm[stream_wind], 0, TRUE);
621                         FSOUND_SetPaused(channels[stream_wind], FALSE);
622                         FSOUND_SetVolume(channels[stream_wind], 256);
623                 }
624
625                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
626                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
627                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
628                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
629
630                 FSOUND_Sample_Free(samp[footstepsound]);
631                 FSOUND_Sample_Free(samp[footstepsound2]);
632                 FSOUND_Sample_Free(samp[footstepsound3]);
633                 FSOUND_Sample_Free(samp[footstepsound4]);
634                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
635                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
636                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
637                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
638                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
639                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
640                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
641                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
642
643                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
644
645                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
646
647                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
648
649
650
651
652                 temptexdetail=texdetail;
653                 if(texdetail>1)texdetail=4;
654                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
655                         ":Data:Textures:Skybox(snow):Left.jpg",
656                         ":Data:Textures:Skybox(snow):Back.jpg",
657                         ":Data:Textures:Skybox(snow):Right.jpg",
658                         ":Data:Textures:Skybox(snow):Up.jpg",
659                         ":Data:Textures:Skybox(snow):Down.jpg",
660                         ":Data:Textures:Skybox(snow):Cloud.jpg",
661                         ":Data:Textures:Skybox(snow):Reflect.jpg");
662
663
664
665
666                 texdetail=temptexdetail;
667         }
668         if(environment==desertenvironment){
669                 windvector=0;
670                 windvector.z=2;
671                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
672                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
673                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
674                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
675
676
677                 if(ambientsound){
678                         //PlaySoundEx( desertambient, samp[desertambient], NULL, TRUE);
679                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, TRUE);
680                         FSOUND_SetPaused(channels[stream_desertambient], FALSE);
681                         FSOUND_SetVolume(channels[stream_desertambient], 256);
682                 }
683
684                 FSOUND_Sample_Free(samp[footstepsound]);
685                 FSOUND_Sample_Free(samp[footstepsound2]);
686                 FSOUND_Sample_Free(samp[footstepsound3]);
687                 FSOUND_Sample_Free(samp[footstepsound4]);
688                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
689                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
690                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
691                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
692                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
693                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
694                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
695                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
696
697                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
698
699                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
700
701                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
702
703
704
705                 temptexdetail=texdetail;
706                 if(texdetail>1)texdetail=4;
707                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
708                         ":Data:Textures:Skybox(sand):Left.jpg",
709                         ":Data:Textures:Skybox(sand):Back.jpg",
710                         ":Data:Textures:Skybox(sand):Right.jpg",
711                         ":Data:Textures:Skybox(sand):Up.jpg",
712                         ":Data:Textures:Skybox(sand):Down.jpg",
713                         ":Data:Textures:Skybox(sand):Cloud.jpg",
714                         ":Data:Textures:Skybox(sand):Reflect.jpg");
715
716
717
718
719                 texdetail=temptexdetail;
720         }
721         if(environment==grassyenvironment){
722                 windvector=0;
723                 windvector.z=2;
724                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
725                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
726                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
727                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
728
729                 if(ambientsound){
730                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, TRUE);
731                         FSOUND_SetPaused(channels[stream_wind], FALSE);
732                         FSOUND_SetVolume(channels[stream_wind], 100);
733                 }
734
735                 FSOUND_Sample_Free(samp[footstepsound]);
736                 FSOUND_Sample_Free(samp[footstepsound2]);
737                 FSOUND_Sample_Free(samp[footstepsound3]);
738                 FSOUND_Sample_Free(samp[footstepsound4]);
739                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass1.ogg", FSOUND_HW3D, 0, 0);
740                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass2.ogg", FSOUND_HW3D, 0, 0);
741                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
742                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
743                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
744                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
745                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
746                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
747
748                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
749
750                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
751
752                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
753
754
755
756                 temptexdetail=texdetail;
757                 if(texdetail>1)texdetail=4;
758                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
759                         ":Data:Textures:Skybox(grass):Left.jpg",
760                         ":Data:Textures:Skybox(grass):Back.jpg",
761                         ":Data:Textures:Skybox(grass):Right.jpg",
762                         ":Data:Textures:Skybox(grass):Up.jpg",
763                         ":Data:Textures:Skybox(grass):Down.jpg",
764                         ":Data:Textures:Skybox(grass):Cloud.jpg",
765                         ":Data:Textures:Skybox(grass):Reflect.jpg");
766
767
768
769                 texdetail=temptexdetail;
770         }
771         temptexdetail=texdetail;
772         texdetail=1;
773         terrain.load(":Data:Textures:heightmap.png");
774
775         texdetail=temptexdetail;
776 }
777
778
779 void    Game::Loadlevel(int which){
780         stealthloading=0;
781
782         if(which==0)Loadlevel((char *)":Data:Maps:map1");
783         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
784         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
785         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
786         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
787         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
788         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
789         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
790         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
791         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
792         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
793         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
794         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
795         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
796         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
797         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
798         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
799         else Loadlevel((char *)":Data:Maps:mapsave");
800
801         whichlevel=which;
802 }
803
804 /*char * Game::MD5_string (unsigned char *string){
805 char temp[50];
806 char temp2[100];
807
808 strcpy(temp2,(const char *)string);
809 strcat((char *)temp2,(const char *)"Lugaru");                                   
810 sprintf (temp, "%d",strlen((char *)temp2));
811 strcat((char *)temp2,temp);                                     
812
813 MD5 context;
814 unsigned int len = strlen ( (char *)temp2);
815
816 context.update   ((unsigned char *)temp2, len);
817 context.finalize ();
818
819 return context.hex_digest();
820 }*/
821
822
823
824 void    Game::Loadlevel(char *name){
825         int i,j,k,l,m;
826         static int oldlevel;
827         int templength;
828         float lamefloat;
829         int lameint;
830
831         float headprop,legprop,armprop,bodyprop;
832
833         LOGFUNC;
834
835         LOG(std::string("Loading level...") + name);
836
837         if(!gameon)visibleloading=1;
838
839         if(stealthloading)visibleloading=0;
840
841         if(!stillloading)loadtime=0;
842         gamestarted=1;
843
844         numenvsounds=0;
845         //visibleloading=1;
846         if(tutoriallevel!=-1)tutoriallevel=0;
847         else tutoriallevel=1;
848
849         if(tutoriallevel==1)tutorialstage=0;
850         if(tutorialstage==0){
851                 tutorialstagetime=0;
852                 tutorialmaxtime=1;
853         }
854         loadingstuff=1;
855         if(!firstload){
856                 oldlevel=50;
857         }
858         FSOUND_SetPaused(channels[whooshsound], TRUE);
859         FSOUND_SetPaused(channels[stream_firesound], TRUE);
860
861         int mapvers;
862         FILE                    *tfile;
863         tfile=fopen( name, "rb" );
864         if(tfile)
865         {
866                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
867
868
869                 scoreadded=0;
870                 windialogue=0;
871
872                 hostiletime=0;
873
874                 won=0;
875
876                 //campaign=0;
877                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
878
879                 numdialogues=0;
880
881                 for(i=0;i<20;i++)
882                 {
883                         dialoguegonethrough[i]=0;
884                 }
885
886                 indialogue=-1;
887                 cameramode=0;
888
889                 damagedealt=0;
890                 damagetaken=0;
891
892                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
893
894                 if(difficulty!=2)minimap=1;
895                 else minimap=0;
896
897                 numhotspots=0;
898                 currenthotspot=-1;
899                 bonustime=1;
900
901                 skyboxtexture=1;
902                 skyboxr=1;
903                 skyboxg=1;
904                 skyboxb=1;
905
906                 freeze=0;
907                 winfreeze=0;
908
909                 for(i=0;i<100;i++)
910                 {
911                         bonusnum[i]=0;
912                 }
913
914                 numfalls=0;
915                 numflipfail=0;
916                 numseen=0;
917                 numstaffattack=0;
918                 numswordattack=0;
919                 numknifeattack=0;
920                 numunarmedattack=0;
921                 numescaped=0;
922                 numflipped=0;
923                 numwallflipped=0;
924                 numthrowkill=0;
925                 numafterkill=0;
926                 numreversals=0;
927                 numattacks=0;
928                 maxalarmed=0;
929                 numresponded=0;
930
931                 bonustotal=startbonustotal;
932                 bonus=0;
933                 gameon=1;
934                 changedelay=0;
935                 if(console)
936                 {
937                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
938                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
939                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
940                         freeze=0;
941                         console=0;
942                 }
943
944                 if(!stealthloading)
945                 {
946                         terrain.numdecals=0;
947                         sprites.numsprites=0;
948                         for(i=0;i<objects.numobjects;i++)
949                         {
950                                 objects.model[i].numdecals=0;
951                         }
952
953                         j=objects.numobjects;
954                         for(i=0;i<j;i++)
955                         {
956                                 objects.DeleteObject(0);
957                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
958                         }
959
960                         for(i=0;i<subdivision;i++)
961                         {
962                                 for(j=0;j<subdivision;j++)
963                                 {
964                                         terrain.patchobjectnum[i][j]=0;
965                                 }
966                         }
967                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
968                 }
969
970                 weapons.numweapons=0;
971
972                 funpackf(tfile, "Bi", &mapvers);
973                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
974                 else indemo=0;
975                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
976                 else maptype=mapkilleveryone;
977                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
978                 else hostile=1;
979                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
980                 else
981                 {
982                         viewdistance=100;
983                         fadestart=.6;
984                 }
985                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
986                 else
987                 {
988                         skyboxtexture=1;
989                         skyboxr=1;
990                         skyboxg=1;
991                         skyboxb=1;
992                 }
993                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
994                 else
995                 {
996                         skyboxlightr=skyboxr;
997                         skyboxlightg=skyboxg;
998                         skyboxlightb=skyboxb;
999                 }
1000                 if(!stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons);
1001                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1002                 player[0].originalcoords=player[0].coords;
1003                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1004                 {
1005                         for(j=0;j<player[0].num_weapons;j++)
1006                         {
1007                                 player[0].weaponids[j]=weapons.numweapons;
1008                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1009                                 weapons.owner[weapons.numweapons]=0;
1010                                 weapons.numweapons++;
1011                         }
1012                 }
1013
1014                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1015
1016                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1017                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1018                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1019                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1020
1021                 funpackf(tfile, "Bi", &player[0].numclothes);
1022
1023                 if(mapvers>=9)
1024                 {
1025                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1026                 }
1027                 else
1028                 {
1029                         player[0].whichskin=0;
1030                         player[0].creature=rabbittype;
1031                 }
1032
1033                 for(i=0;i<max_dialogues;i++)
1034                 {
1035                         for(j=0;j<max_dialoguelength;j++)
1036                         {
1037                                 for(k=0;k<128;k++)
1038                                 {
1039                                         dialoguetext[i][j][k]='\0';
1040                                 }
1041                                 for(k=0;k<64;k++)
1042                                 {
1043                                         dialoguename[i][j][k]='\0';
1044                                 }
1045                         }
1046                 }
1047
1048                 player[0].lastattack=-1;
1049                 player[0].lastattack2=-1;
1050                 player[0].lastattack3=-1;
1051
1052                 if(mapvers>=8)
1053                 {
1054                         funpackf(tfile, "Bi", &numdialogues);
1055                         if(numdialogues)
1056                         {
1057                                 for(k=0;k<numdialogues;k++)
1058                                 {
1059                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1060                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1061                                         for(l=0;l<10;l++)
1062                                         {
1063                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1064                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1065                                         }
1066                                         if(numdialogueboxes)
1067                                         {
1068                                                 for(l=0;l<numdialogueboxes[k];l++)
1069                                                 {
1070                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1071                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1072                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1073                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1074                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1075
1076                                                         bool doneread;
1077
1078                                                         funpackf(tfile, "Bi",&templength);
1079                                                         if(templength>128||templength<=0)templength=128;
1080                                                         for(m=0;m<templength;m++){
1081                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1082                                                                 if(dialoguetext[k][l][m]=='\0')break;
1083                                                         }
1084
1085                                                         funpackf(tfile, "Bi",&templength);
1086                                                         if(templength>64||templength<=0)templength=64;
1087                                                         for(m=0;m<templength;m++){
1088                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1089                                                                 if(dialoguename[k][l][m]=='\0'){
1090                                                                         break;  
1091                                                                 }
1092                                                         }
1093                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1094                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1095                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1096
1097                                                         for(m=0;m<10;m++)
1098                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1099
1100                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1101                                                 }
1102                                         }
1103                                 }
1104                         }
1105                 }
1106                 else numdialogues=0;
1107
1108                 if(player[0].numclothes)
1109                 {
1110                         for(k=0;k<player[0].numclothes;k++)
1111                         {
1112                                 funpackf(tfile, "Bi", &templength);
1113                                 for(l=0;l<templength;l++)
1114                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1115                                 player[0].clothes[k][templength]='\0';
1116                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);                                                                        
1117                         }
1118                 }
1119
1120                 funpackf(tfile, "Bi", &environment);
1121
1122                 funpackf(tfile, "Bi", &objects.numobjects);
1123                 if(objects.numobjects)
1124                 {
1125                         for(i=0;i<objects.numobjects;i++)
1126                         {
1127                                 funpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", &objects.type[i],&objects.rotation[i],&objects.rotation2[i], &objects.position[i].x, &objects.position[i].y, &objects.position[i].z,&objects.scale[i]);
1128                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1129                         }
1130                 }
1131
1132                 if(mapvers>=7)
1133                 {
1134                         funpackf(tfile, "Bi", &numhotspots);
1135                         if(numhotspots)
1136                         {
1137                                 for(i=0;i<numhotspots;i++)
1138                                 {
1139                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1140                                         funpackf(tfile, "Bi", &templength);
1141                                         if(templength)
1142                                                 for(l=0;l<templength;l++)
1143                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1144                                         hotspottext[i][templength]='\0';
1145                                         if(hotspottype[i]==-111)indemo=1;
1146                                 }
1147                         }
1148                 }
1149                 else numhotspots=0;
1150
1151                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1152
1153                 if(!stealthloading)
1154                 {
1155                         objects.center=0;
1156                         for(i=0;i<objects.numobjects;i++)
1157                         {
1158                                 objects.center+=objects.position[i];    
1159                         }
1160                         objects.center/=objects.numobjects;
1161
1162
1163                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1164
1165                         float maxdistance=0;
1166                         float tempdist;
1167                         int whichclosest;
1168                         for(i=0;i<objects.numobjects;i++)
1169                         {
1170                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1171                                 if(tempdist>maxdistance)
1172                                 {
1173                                         whichclosest=i;
1174                                         maxdistance=tempdist;
1175                                 }
1176                         }
1177                         objects.radius=fast_sqrt(maxdistance);
1178                 }                               
1179
1180                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1181                 //mapcenter=objects.center;
1182                 //mapradius=objects.radius;
1183
1184                 funpackf(tfile, "Bi", &numplayers);
1185                 int howmanyremoved=0;
1186                 bool removeanother=0;
1187                 if(numplayers>1&&numplayers<maxplayers)
1188                 {
1189                         for(i=1;i<numplayers;i++)
1190                         {
1191                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1192                                 removeanother=0;
1193
1194                                 funpackf(tfile, "Bi Bi Bf Bf Bf Bi",&player[i-howmanyremoved].whichskin,&player[i-howmanyremoved].creature, &player[i-howmanyremoved].coords.x,&player[i-howmanyremoved].coords.y,&player[i-howmanyremoved].coords.z,&player[i-howmanyremoved].num_weapons);
1195                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1196                                 else player[i-howmanyremoved].howactive=typeactive;
1197                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1198                                 else player[i-howmanyremoved].scale=-1;
1199                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1200                                 else player[i-howmanyremoved].immobile=0;
1201                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1202                                 else player[i-howmanyremoved].rotation=0;
1203                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1204                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1205                                         removeanother=1;
1206                                         howmanyremoved++;
1207                                 }
1208                                 if(!removeanother)
1209                                 {
1210                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1211                                         {
1212                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1213                                                 {
1214                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1215                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1216                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1217                                                         weapons.numweapons++;
1218                                                 }
1219                                         }
1220                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1221                                         //player[i-howmanyremoved].numwaypoints=10;
1222                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1223                                         {
1224                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1225                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1226                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1227                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1228                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1229                                         }
1230
1231                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1232                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1233
1234                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1235                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1236                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1237                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1238
1239                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1240                                         else
1241                                         {
1242                                                 headprop=1;
1243                                                 bodyprop=1;
1244                                                 armprop=1;
1245                                                 legprop=1;
1246                                         }
1247                                         if(player[i-howmanyremoved].creature==wolftype)
1248                                         {
1249                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1250                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1251                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1252                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1253                                         }
1254
1255                                         if(player[i-howmanyremoved].creature==rabbittype)
1256                                         {
1257                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1258                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1259                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1260                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1261                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1262                                         }
1263
1264                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1265                                         if(player[i-howmanyremoved].numclothes)
1266                                         {
1267                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1268                                                 {
1269                                                         int templength;
1270                                                         funpackf(tfile, "Bi", &templength);
1271                                                         for(l=0;l<templength;l++)
1272                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1273                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1274                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);                                                                   
1275                                                 }
1276                                         }
1277                                 }
1278                         }
1279                 }
1280                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1281
1282                 numplayers-=howmanyremoved;
1283                 funpackf(tfile, "Bi", &numpathpoints);
1284                 if(numpathpoints>30||numpathpoints<0)
1285                         numpathpoints=0;
1286                 if(numpathpoints)
1287                 {
1288                         for(j=0;j<numpathpoints;j++)
1289                         {
1290                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1291                                 for(k=0;k<numpathpointconnect[j];k++){
1292                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1293                                 }
1294                         }
1295                 }
1296                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1297
1298                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1299
1300                 SetUpLighting();
1301                 if(environment!=oldenvironment)Setenvironment(environment);
1302                 oldenvironment=environment;
1303
1304                 if(!stealthloading)
1305                 {
1306                         j=objects.numobjects;
1307                         objects.numobjects=0;
1308                         for(i=0;i<j;i++)
1309                         {
1310                                 //if(objects.type[i]!=spiketype)
1311                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1312                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1313                         }
1314
1315                         //if(skyboxtexture){
1316                         terrain.DoShadows();
1317                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1318                         objects.DoShadows();
1319                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1320                         /*}
1321                         else terrain.DoLighting();
1322                         */
1323                 }
1324
1325                 fclose(tfile);
1326
1327                 oldlevel=whichlevel;
1328
1329
1330                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1331                 for(i=0;i<numplayers;i++)
1332                 {
1333                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1334                         player[i].burnt=0;
1335                         player[i].bled=0;
1336                         player[i].onfire=0;
1337                         if(i==0||player[i].scale<0)player[i].scale=.2;
1338                         player[i].skeleton.free=0;
1339                         player[i].skeleton.id=i;
1340                         //if(Random()%2==0)player[i].creature=wolftype;
1341                         //else player[i].creature=rabbittype;
1342                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1343                         if(player[i].creature!=wolftype)player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",0);
1344                         else
1345                         {
1346                                 if(player[i].creature!=wolftype){
1347                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
1348                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1349                                 }
1350                                 if(player[i].creature==wolftype){
1351                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
1352                                 }
1353                         }
1354
1355
1356                         int texsize;
1357                         texsize=512*512*3/texdetail/texdetail;
1358                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1359                         //player[i].skeleton.skinText.resize(texsize);
1360
1361                         if(player[i].creature==rabbittype)
1362                         {
1363                                 if(player[i].whichskin==0){
1364                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1365                                 }
1366                                 else if(player[i].whichskin==1){
1367                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1368                                 }
1369                                 else if(player[i].whichskin==2){
1370                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1371                                 }
1372                                 else if(player[i].whichskin==3){
1373                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1374                                 }
1375                                 else if(player[i].whichskin==4){
1376                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1377                                 }
1378                                 else if(player[i].whichskin==5){
1379                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1380                                 }
1381                                 else if(player[i].whichskin==6){
1382                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1383                                 }
1384                                 else if(player[i].whichskin==7){
1385                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1386                                 }
1387                                 else if(player[i].whichskin==8){
1388                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1389                                 }
1390                                 else if(player[i].whichskin==9){
1391                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1392                                 }
1393                         }
1394                         if(player[i].creature==wolftype)
1395                         {
1396                                 //k=abs(Random()%3);
1397                                 if(player[i].whichskin==0){
1398                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1399                                 }
1400                                 else if(player[i].whichskin==1){
1401                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1402                                 }
1403                                 else if(player[i].whichskin==2){
1404                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1405                                 }
1406                         }
1407
1408                         if(player[i].numclothes)
1409                         {
1410                                 for(j=0;j<player[i].numclothes;j++)
1411                                 {
1412                                         tintr=player[i].clothestintr[j];
1413                                         tintg=player[i].clothestintg[j];
1414                                         tintb=player[i].clothestintb[j];
1415                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1416                                 }
1417                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1418                         }
1419
1420                         player[i].currentanimation=bounceidleanim;
1421                         player[i].targetanimation=bounceidleanim;
1422                         player[i].currentframe=0;
1423                         player[i].targetframe=1;
1424                         player[i].target=0;
1425                         player[i].speed=1+(float)(Random()%100)/1000;
1426                         if(difficulty==0)player[i].speed-=.2;
1427                         if(difficulty==1)player[i].speed-=.1;
1428
1429                         player[i].velocity=0;
1430                         player[i].oldcoords=player[i].coords;
1431                         player[i].realoldcoords=player[i].coords;
1432
1433                         player[i].id=i;
1434                         player[i].skeleton.id=i;
1435                         player[i].updatedelay=0;
1436                         player[i].normalsupdatedelay=0;
1437
1438                         player[i].aitype=passivetype;
1439                         player[i].aitarget=0;
1440                         player[i].madskills=0;
1441
1442                         if(i==0)
1443                         {
1444                                 player[i].proportionhead=1.2;
1445                                 player[i].proportionbody=1.05;
1446                                 player[i].proportionarms=1.00;
1447                                 player[i].proportionlegs=1.1;
1448                                 player[i].proportionlegs.y=1.05;
1449                         }
1450                         player[i].headless=0;
1451                         player[i].currentoffset=0;
1452                         player[i].targetoffset=0;
1453                         /*player[i].armorhead=1;
1454                         player[i].armorhigh=1;
1455                         player[i].armorlow=1;
1456                         player[i].protectionhead=1;
1457                         player[i].protectionhigh=1;
1458                         player[i].protectionlow=1;
1459                         player[i].metalhead=1;
1460                         player[i].metalhigh=1;
1461                         player[i].metallow=1;
1462                         player[i].power=1;
1463                         player[i].speedmult=1;*/
1464
1465                         player[i].damagetolerance=200;
1466
1467                         if(player[i].creature==wolftype)
1468                         {
1469                                 /*player[i].proportionhead=1.1;
1470                                 player[i].proportionbody=1.1;
1471                                 player[i].proportionarms=1.1;
1472                                 player[i].proportionlegs=1.1;
1473                                 player[i].proportionlegs.y=1.1;*/
1474                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1475
1476                                 player[i].damagetolerance=300;
1477                         }                               
1478
1479                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1480                         if(cellophane)
1481                         {
1482                                 player[i].proportionhead.z=0;
1483                                 player[i].proportionbody.z=0;
1484                                 player[i].proportionarms.z=0;
1485                                 player[i].proportionlegs.z=0;
1486                         }
1487
1488                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1489
1490                         player[i].headmorphness=0;
1491                         player[i].targetheadmorphness=1;
1492                         player[i].headmorphstart=0;
1493                         player[i].headmorphend=0;
1494
1495                         player[i].pausetime=0;
1496
1497                         player[i].dead=0;
1498                         player[i].jumppower=5;
1499                         player[i].damage=0;
1500                         player[i].permanentdamage=0;
1501                         player[i].superpermanentdamage=0;
1502
1503                         player[i].forwardkeydown=0;
1504                         player[i].leftkeydown=0;
1505                         player[i].backkeydown=0;
1506                         player[i].rightkeydown=0;
1507                         player[i].jumpkeydown=0;
1508                         player[i].crouchkeydown=0;
1509                         player[i].throwkeydown=0;
1510
1511                         player[i].collided=-10;
1512                         player[i].loaded=1;
1513                         player[i].bloodloss=0;
1514                         player[i].weaponactive=-1;
1515                         player[i].weaponstuck=-1;
1516                         player[i].bleeding=0;
1517                         player[i].deathbleeding=0;
1518                         player[i].stunned=0;
1519                         player[i].hasvictim=0;
1520                         player[i].wentforweapon=0;
1521                 }
1522
1523                 player[0].aitype=playercontrolled;
1524                 player[0].weaponactive=-1;
1525
1526                 if(difficulty==1)
1527                 {
1528                         //player[0].speedmult=1/.9;
1529                         player[0].power=1/.9;
1530                 }
1531
1532                 if(difficulty==0)
1533                 {
1534                         //player[0].speedmult=1/.8;
1535                         player[0].power=1/.8;
1536                 }
1537
1538                 //player[0].weaponstuck=1;
1539
1540                 if(difficulty==1)player[0].damagetolerance=250;
1541                 if(difficulty==0)player[0].damagetolerance=300;
1542                 if(difficulty==0)player[0].armorhead*=1.5;
1543                 if(difficulty==0)player[0].armorhigh*=1.5;
1544                 if(difficulty==0)player[0].armorlow*=1.5;
1545                 cameraloc=player[0].coords;
1546                 cameraloc.y+=5;
1547                 rotation=player[0].rotation;
1548
1549                 hawkcoords=player[0].coords;
1550                 hawkcoords.y+=30;
1551
1552                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1553                 //weapons.numweapons=numplayers;
1554                 for(i=0;i<weapons.numweapons;i++)
1555                 {
1556                         weapons.bloody[i]=0;
1557                         weapons.blooddrip[i]=0;
1558                         weapons.blooddripdelay[i]=0;
1559                         weapons.onfire[i]=0;
1560                         weapons.flamedelay[i]=0;
1561                         weapons.damage[i]=0;
1562                         //weapons.type[i]=sword;
1563                         if(weapons.type[i]==sword){
1564                                 weapons.mass[i]=1.5;
1565                                 weapons.tipmass[i]=1;
1566                                 weapons.length[i]=.8;
1567                         }
1568                         if(weapons.type[i]==staff){
1569                                 weapons.mass[i]=2;
1570                                 weapons.tipmass[i]=1;
1571                                 weapons.length[i]=1.5;
1572                         }
1573                         if(weapons.type[i]==knife){
1574                                 weapons.mass[i]=1;
1575                                 weapons.tipmass[i]=1.2;
1576                                 weapons.length[i]=.25;
1577                         }
1578                         weapons.position[i]=-1000;
1579                         weapons.tippoint[i]=-1000;
1580                 }
1581
1582 /*              for(i=0;i<32;i++){
1583                         //if(i<16||i>20)                                
1584                         FSOUND_StopSound(i);
1585                 }
1586 */
1587                 LOG("Starting background music...");
1588
1589                 FSOUND_StopSound(FSOUND_ALL);
1590                 if(environment==snowyenvironment)
1591                 {
1592                         if(ambientsound)
1593                         {
1594                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
1595                                 FSOUND_SetPaused(channels[stream_wind], FALSE);
1596                                 FSOUND_SetVolume(channels[stream_wind], 256);
1597                         }
1598                 }
1599                 else if(environment==desertenvironment)
1600                 {
1601                         if(ambientsound)
1602                         {
1603                                 //PlaySoundEx(desertambient,
1604                                 //      samp[desertambient], NULL, TRUE);
1605                                 PlayStreamEx(stream_desertambient,
1606                                         strm[stream_desertambient], NULL, TRUE);
1607                                 FSOUND_SetPaused(channels[stream_desertambient], FALSE);
1608                                 FSOUND_SetVolume(channels[stream_desertambient], 256);
1609                         }
1610                 }
1611                 else if(environment==grassyenvironment)
1612                 {
1613                         if(ambientsound)
1614                         {
1615                                 //PlaySoundEx(wind, samp[wind], NULL, TRUE);
1616                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
1617                                 FSOUND_SetPaused(channels[stream_wind], FALSE);
1618                                 FSOUND_SetVolume(channels[stream_wind], 100);
1619                         }
1620                 }
1621                 oldmusicvolume[0]=0;
1622                 oldmusicvolume[1]=0;
1623                 oldmusicvolume[2]=0;
1624                 oldmusicvolume[3]=0;
1625
1626
1627                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1628                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1629                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1630                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1631                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1632                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1633                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1634                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1635                 */
1636
1637                 if(!firstload)
1638                 {
1639                         firstload=1;
1640                 }
1641         }
1642         leveltime=0;
1643         loadingstuff=0;
1644         visibleloading=0;
1645 }
1646
1647 void    Game::Tick()
1648 {
1649         static int i,k,j,l,m;
1650         static XYZ facing,flatfacing,absflatfacing;
1651         static XYZ rotatetarget;
1652         static bool oldkey;
1653         static float oldtargetrotation;
1654         static int target, numgood;
1655         static XYZ tempcoords1,tempcoords2;
1656         static XYZ test;
1657         static XYZ test2;
1658         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1659         static int whichhit;
1660         static bool donesomething;
1661         static bool oldjumpkeydown;
1662
1663         int templength;
1664
1665         float headprop,bodyprop,armprop,legprop;
1666
1667         if(newnetmessages){
1668                 newnetmessages=0;
1669                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
1670                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
1671                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
1672
1673                 for(k=14;k>=2;k--){
1674                         for(j=0;j<255;j++){
1675                                 consoletext[k][j]=consoletext[k-1][j];
1676                         }
1677                         consolechars[k]=consolechars[k-1];
1678                 }
1679                 for(k=14;k>=2;k--){
1680                         for(j=0;j<255;j++){
1681                                 displaytext[k][j]=displaytext[k-1][j];
1682                         }
1683                         displaychars[k]=displaychars[k-1];
1684                         displaytime[k]=displaytime[k-1];
1685                 }
1686                 for(j=0;j<255;j++){
1687                         consoletext[1][j]=' ';
1688                         displaytext[1][j]=' ';
1689                 }
1690                 sprintf (consoletext[1], netmessages);
1691                 sprintf (displaytext[1], netmessages);
1692                 consolechars[1]=255;
1693                 displaychars[1]=255;
1694                 displaytime[1]=0;
1695         }
1696
1697         for(i=0;i<15;i++){
1698                 displaytime[i]+=multiplier;
1699         }
1700
1701         static unsigned char    theKeyMap[16];
1702         GetKeys( theKeyMap );
1703
1704         keyboardfrozen=0;
1705
1706
1707         static bool mainmenutogglekeydown;
1708         if(!console){
1709                 if(mainmenu&&endgame==1)mainmenu=10;
1710                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1711                         for(j=0;j<255;j++){
1712                                 displaytext[0][j]=' ';
1713                         }
1714                         displaychars[0]=0;
1715                         displayselected=0;
1716                         entername=0;
1717                         mainmenutogglekeydown=1;
1718                 }
1719                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||(mainmenu==12&&!tryquit)||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17||mainmenu==10)){
1720                         selected=-1;
1721                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1722                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1723                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1724                                 else if(mainmenu==0&&winfreeze){
1725                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1726                                         stealthloading=1;
1727                                         else stealthloading=0;
1728
1729                                         if(!stealthloading){
1730                                         float gLoc[3]={0,0,0};
1731                                         float vel[3]={0,0,0};
1732                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
1733                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
1734                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1735                                         FSOUND_SetVolume(channels[firestartsound], 256);
1736                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
1737                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1738
1739                                         flashr=1;
1740                                         flashg=0;
1741                                         flashb=0;
1742                                         flashamount=1;
1743                                         flashdelay=1;
1744                                         }
1745
1746                                         startbonustotal=0;
1747
1748                                         for(i=0;i<campaignnumlevels;i++){
1749                                         levelvisible[i]=0;
1750                                         levelhighlight[i]=0;
1751                                         }
1752
1753                                         levelorder[0]=0;
1754                                         levelvisible[0]=1;
1755                                         if(accountcampaignchoicesmade[accountactive])
1756                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1757                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1758                                         levelvisible[levelorder[i+1]]=1;
1759                                         }
1760                                         int whichlevelstart;
1761                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1762                                         if(whichlevelstart<0){
1763                                         campaignchoicenum=1;
1764                                         campaignchoicewhich[0]=0;
1765                                         }
1766                                         else
1767                                         {
1768                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1769                                         if(campaignchoicenum)
1770                                         for(i=0;i<campaignchoicenum;i++){
1771                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1772                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1773                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1774                                         }
1775                                         }
1776
1777                                         loading=2;
1778                                         loadtime=0;
1779                                         targetlevel=7;
1780                                         if(firstload)TickOnceAfter();
1781                                         if(!firstload)LoadStuff();
1782                                         //else {
1783                                         for(i=0;i<255;i++){
1784                                         mapname[i]='\0';
1785                                         }
1786                                         mapname[0]=':';
1787                                         mapname[1]='D';
1788                                         mapname[2]='a';
1789                                         mapname[3]='t';
1790                                         mapname[4]='a';
1791                                         mapname[5]=':';
1792                                         mapname[6]='M';
1793                                         mapname[7]='a';
1794                                         mapname[8]='p';
1795                                         mapname[9]='s';
1796                                         mapname[10]=':';
1797
1798                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1799                                         //accountcampaignchoicesmade[accountactive]++;
1800
1801
1802                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1803                                         whichchoice=0;
1804                                         visibleloading=1;
1805                                         stillloading=1;
1806                                         Loadlevel(mapname);
1807                                         campaign=1;
1808                                         mainmenu=0;
1809                                         gameon=1;
1810                                         FSOUND_SetPaused(channels[music3], TRUE);
1811
1812                                         stealthloading=0;*/
1813                                 }
1814                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1815                                 if(mainmenu&&musictoggle){
1816                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1817                                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
1818                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
1819                                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
1820                                                 FSOUND_SetVolume(channels[stream_music3], 256);
1821                                                 FSOUND_SetPaused(channels[music1], TRUE);
1822                                         }
1823                                 }
1824                                 if(!mainmenu){
1825                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
1826                                         FSOUND_SetPaused(channels[music1], FALSE);
1827                                 }
1828                         }
1829                         if(mainmenu==3){
1830                                 float gLoc[3]={0,0,0};
1831                                 float vel[3]={0,0,0};
1832                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1833                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1834                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1835                                 FSOUND_SetVolume(channels[fireendsound], 256);
1836                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1837                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1838
1839                                 flashr=1;
1840                                 flashg=0;
1841                                 flashb=0;
1842                                 flashamount=1;
1843                                 flashdelay=1;
1844
1845                                 if(newdetail>2)newdetail=detail;
1846                                 if(newdetail<0)newdetail=detail;
1847                                 if(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                                 if(newscreenwidth==1920&&newscreenheight==1200)whichres=8;
2120
2121                                 if(whichres==-1||whichres==8){
2122                                         newscreenwidth=640;
2123                                         newscreenheight=480;
2124                                 }
2125                                 if(whichres==0){
2126                                         newscreenwidth=800;
2127                                         newscreenheight=600;
2128                                 }
2129                                 if(whichres==1){
2130                                         newscreenwidth=1024;
2131                                         newscreenheight=768;
2132                                 }
2133                                 if(whichres==2){
2134                                         newscreenwidth=1280;
2135                                         newscreenheight=1024;
2136                                 }
2137                                 if(whichres==3){
2138                                         newscreenwidth=1600;
2139                                         newscreenheight=1200;
2140                                 }
2141                                 if(whichres==4){
2142                                         newscreenwidth=840;
2143                                         newscreenheight=524;
2144                                 }
2145                                 if(whichres==5){
2146                                         newscreenwidth=1024;
2147                                         newscreenheight=640;
2148                                 }
2149                                 if(whichres==6){
2150                                         newscreenwidth=1344;
2151                                         newscreenheight=840;
2152                                 }
2153                                 if(whichres==7){
2154                                         newscreenwidth=1920;
2155                                         newscreenheight=1200;
2156                                 }
2157                         }
2158                         if(Button()&&!oldbutton&&selected==1){
2159                                 newdetail++;
2160                                 if(newdetail>2)newdetail=0;
2161                         }
2162                         if(Button()&&!oldbutton&&selected==2){
2163                                 bloodtoggle++;
2164                                 if(bloodtoggle>2)bloodtoggle=0;
2165                         }
2166                         if(Button()&&!oldbutton&&selected==3){
2167                                 difficulty++;
2168                                 if(difficulty>2)difficulty=0;
2169                         }
2170                         if(Button()&&!oldbutton&&selected==4){
2171                                 ismotionblur=1-ismotionblur;
2172                         }
2173                         if(Button()&&!oldbutton&&selected==5){
2174                                 decals=1-decals;
2175                         }
2176                         if(Button()&&!oldbutton&&selected==6){
2177                                 musictoggle=1-musictoggle;
2178
2179                                 if(!musictoggle){
2180                                         FSOUND_SetPaused(channels[music1], TRUE);
2181                                         FSOUND_SetPaused(channels[stream_music2], TRUE);
2182                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
2183
2184                                         for(i=0;i<4;i++){
2185                                                 oldmusicvolume[i]=0;
2186                                                 musicvolume[i]=0;
2187                                         }
2188                                 }
2189
2190                                 if(musictoggle){
2191                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
2192                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
2193                                         FSOUND_SetVolume(channels[stream_music3], 256);                         
2194                                 }
2195                         }
2196                         if(Button()&&!oldbutton&&selected==9){
2197                                 invertmouse=1-invertmouse;
2198                         }
2199                         if(Button()&&!oldbutton&&selected==10){
2200                                 usermousesensitivity+=.2;
2201                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2202                         }
2203                         if(Button()&&!oldbutton&&selected==11){
2204                                 volume+=.1f;
2205                                 if(volume>1.0001f)volume=0;
2206                                 FSOUND_SetSFXMasterVolume((int)(volume*255));
2207                         }
2208                         if(Button()&&!oldbutton&&selected==7){
2209                                 /*float gLoc[3]={0,0,0};
2210                                 float vel[3]={0,0,0};
2211                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2212                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2213                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2214                                 FSOUND_SetVolume(channels[firestartsound], 256);
2215                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2216                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2217                                 */
2218                                 flashr=1;
2219                                 flashg=0;
2220                                 flashb=0;
2221                                 flashamount=1;
2222                                 flashdelay=1;
2223
2224                                 //options
2225
2226                                 mainmenu=4;             
2227                                 keyselect=-1;
2228                         }
2229                         if(Button()&&!oldbutton&&selected==8){
2230                                 float gLoc[3]={0,0,0};
2231                                 float vel[3]={0,0,0};
2232                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2233                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2234                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2235                                 FSOUND_SetVolume(channels[fireendsound], 256);
2236                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2237                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2238
2239                                 flashr=1;
2240                                 flashg=0;
2241                                 flashb=0;
2242                                 flashamount=1;
2243                                 flashdelay=1;
2244
2245                                 if(newdetail>2)newdetail=detail;
2246                                 if(newdetail<0)newdetail=detail;
2247                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2248                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2249                                 if(newscreenheight>3000)newscreenheight=screenheight;
2250                                 if(newscreenheight<0)newscreenheight=screenheight;
2251
2252
2253                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2254                                 opstream << "Screenwidth:\n";
2255                                 opstream << newscreenwidth;
2256                                 opstream << "\nScreenheight:\n";
2257                                 opstream << newscreenheight;
2258                                 opstream << "\nMouse sensitivity:\n";
2259                                 opstream << usermousesensitivity;
2260                                 opstream << "\nBlur(0,1):\n";
2261                                 opstream << ismotionblur;
2262                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2263                                 opstream << newdetail;
2264                                 opstream << "\nFloating jump:\n";
2265                                 opstream << floatjump;
2266                                 opstream << "\nMouse jump:\n";
2267                                 opstream << mousejump;
2268                                 opstream << "\nAmbient sound:\n";
2269                                 opstream << ambientsound;
2270                                 opstream << "\nBlood (0,1,2):\n";
2271                                 opstream << bloodtoggle;
2272                                 opstream << "\nAuto slomo:\n";
2273                                 opstream << autoslomo;
2274                                 opstream << "\nFoliage:\n";
2275                                 opstream << foliage;
2276                                 opstream << "\nMusic:\n";
2277                                 opstream << musictoggle;
2278                                 opstream << "\nTrilinear:\n";
2279                                 opstream << trilinear;
2280                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2281                                 opstream << decals;
2282                                 opstream << "\nInvert mouse:\n";
2283                                 opstream << invertmouse;
2284                                 opstream << "\nGamespeed:\n";
2285                                 if(oldgamespeed==0)oldgamespeed=1;
2286                                 opstream << oldgamespeed;
2287                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2288                                 opstream << difficulty;
2289                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2290                                 opstream << damageeffects;
2291                                 opstream << "\nText:\n";
2292                                 opstream << texttoggle;
2293                                 opstream << "\nDebug:\n";
2294                                 opstream << debugmode;
2295                                 opstream << "\nVBL Sync:\n";
2296                                 opstream << vblsync;
2297                                 opstream << "\nShow Points:\n";
2298                                 opstream << showpoints;
2299                                 opstream << "\nAlways Blur:\n";
2300                                 opstream << alwaysblur;
2301                                 opstream << "\nImmediate mode (turn on on G5):\n";
2302                                 opstream << immediate;
2303                                 opstream << "\nVelocity blur:\n";
2304                                 opstream << velocityblur;
2305                             opstream << "\nVolume:\n";
2306                         opstream << volume;
2307                                 opstream << "\nForward key:\n";
2308                                 opstream << KeyToChar(forwardkey);
2309                                 opstream << "\nBack key:\n";
2310                                 opstream << KeyToChar(backkey);
2311                                 opstream << "\nLeft key:\n";
2312                                 opstream << KeyToChar(leftkey);
2313                                 opstream << "\nRight key:\n";
2314                                 opstream << KeyToChar(rightkey);
2315                                 opstream << "\nJump key:\n";
2316                                 opstream << KeyToChar(jumpkey);
2317                                 opstream << "\nCrouch key:\n";
2318                                 opstream << KeyToChar(crouchkey);
2319                                 opstream << "\nDraw key:\n";
2320                                 opstream << KeyToChar(drawkey);
2321                                 opstream << "\nThrow key:\n";
2322                                 opstream << KeyToChar(throwkey);
2323                                 opstream << "\nAttack key:\n";
2324                                 opstream << KeyToChar(attackkey);
2325                                 opstream << "\nChat key:\n";
2326                                 opstream << KeyToChar(chatkey);
2327                                 opstream.close();
2328
2329                                 if(mainmenu==3&&gameon)mainmenu=2;
2330                                 if(mainmenu==3&&!gameon)mainmenu=1;
2331                         }
2332                         if(Button())oldbutton=1;
2333                         else oldbutton=0;
2334                 }
2335                 if(mainmenu==4){
2336                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2337                                 float gLoc[3]={0,0,0};
2338                                 float vel[3]={0,0,0};
2339                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2340                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2341                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2342                                 FSOUND_SetVolume(channels[firestartsound], 256);
2343                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2344                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2345                         }
2346                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2347                                 keyselect=selected;
2348                                 oldbuttons[0]=1;
2349                                 oldbuttons[1]=1;
2350                                 oldbuttons[2]=1;
2351                         }
2352                         if(keyselect!=-1){
2353                                 for(i=0;i<3;i++)
2354                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2355                                 for(i=0;i<140;i++){
2356                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2357                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2358                                                         float gLoc[3]={0,0,0};
2359                                                         float vel[3]={0,0,0};
2360                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2361                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2362                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2363                                                         FSOUND_SetVolume(channels[fireendsound], 256);
2364                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
2365                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2366
2367                                                         int keynum;
2368                                                         keynum=i;
2369                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2370                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2371
2372
2373
2374                                                         if(keyselect==0)forwardkey=keynum;
2375                                                         if(keyselect==1)backkey=keynum;
2376                                                         if(keyselect==2)leftkey=keynum;
2377                                                         if(keyselect==3)rightkey=keynum;
2378                                                         if(keyselect==4)crouchkey=keynum;
2379                                                         if(keyselect==5)jumpkey=keynum;
2380                                                         if(keyselect==6)drawkey=keynum;
2381                                                         if(keyselect==7)throwkey=keynum;
2382                                                         if(keyselect==8)attackkey=keynum;
2383                                                         keyselect=-1;
2384                                                 }
2385                                         }
2386                                 }}
2387                         if(Button()&&!oldbutton&&selected==9){
2388                                 float gLoc[3]={0,0,0};
2389                                 float vel[3]={0,0,0};
2390                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2391                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2392                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2393                                 FSOUND_SetVolume(channels[fireendsound], 256);
2394                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2395                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2396
2397                                 flashr=1;
2398                                 flashg=0;
2399                                 flashb=0;
2400                                 flashamount=1;
2401                                 flashdelay=1;
2402
2403                                 mainmenu=3;
2404
2405                                 if(newdetail>2)newdetail=detail;
2406                                 if(newdetail<0)newdetail=detail;
2407                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2408                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2409                                 if(newscreenheight>3000)newscreenheight=screenheight;
2410                                 if(newscreenheight<0)newscreenheight=screenheight;
2411                         }
2412                 }
2413
2414                 if(mainmenu==5){
2415                         if(accountcampaignchoicesmade[accountactive]>8&&!registered){
2416                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
2417                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
2418                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
2419                                 FSOUND_SetVolume(channels[stream_music3], 256);
2420
2421                                 gameon=0;
2422                                 mainmenu=12;
2423                                 accountcampaignchoicesmade[accountactive]=0;
2424                                 accountcampaignscore[accountactive]=0;
2425                                 accountcampaigntime[accountactive]=0;
2426
2427                                 float gLoc[3]={0,0,0};
2428                                 float vel[3]={0,0,0};
2429                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2430                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2431                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2432                                 FSOUND_SetVolume(channels[fireendsound], 256);
2433                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2434                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2435
2436                                 flashr=1;
2437                                 flashg=0;
2438                                 flashb=0;
2439                                 flashamount=1;
2440                                 flashdelay=1;
2441                         }
2442
2443                         if(endgame==2){
2444                                 accountcampaignchoicesmade[accountactive]=0;
2445                                 accountcampaignscore[accountactive]=0;
2446                                 accountcampaigntime[accountactive]=0;
2447                                 endgame=0;
2448                         }
2449
2450                         if(Button()&&!oldbutton&&selected==1){                  
2451                                 float gLoc[3]={0,0,0};
2452                                 float vel[3]={0,0,0};
2453                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2454                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2455                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2456                                 FSOUND_SetVolume(channels[firestartsound], 256);
2457                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2458                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2459
2460                                 flashr=1;
2461                                 flashg=0;
2462                                 flashb=0;
2463                                 flashamount=1;
2464                                 flashdelay=1;
2465
2466                                 startbonustotal=0;
2467
2468                                 loading=2;
2469                                 loadtime=0;
2470                                 targetlevel=-1;
2471                                 if(firstload)TickOnceAfter();
2472                                 if(!firstload)LoadStuff();
2473                                 else {
2474                                         Loadlevel(-1);
2475                                 }
2476
2477                                 mainmenu=0;
2478                                 gameon=1;
2479                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2480                         }
2481                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){                       
2482                                 float gLoc[3]={0,0,0};
2483                                 float vel[3]={0,0,0};
2484                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2485                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2486                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2487                                 FSOUND_SetVolume(channels[firestartsound], 256);
2488                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2489                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2490
2491                                 flashr=1;
2492                                 flashg=0;
2493                                 flashb=0;
2494                                 flashamount=1;
2495                                 flashdelay=1;
2496
2497                                 startbonustotal=0;
2498
2499                                 loading=2;
2500                                 loadtime=0;
2501                                 targetlevel=7;
2502                                 if(firstload)TickOnceAfter();
2503                                 if(!firstload)LoadStuff();
2504                                 //else {
2505                                 for(i=0;i<255;i++){
2506                                         mapname[i]='\0';
2507                                 }
2508                                 mapname[0]=':';
2509                                 mapname[1]='D';
2510                                 mapname[2]='a';
2511                                 mapname[3]='t';
2512                                 mapname[4]='a';
2513                                 mapname[5]=':';
2514                                 mapname[6]='M';
2515                                 mapname[7]='a';
2516                                 mapname[8]='p';
2517                                 mapname[9]='s';
2518                                 mapname[10]=':';
2519                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2520                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2521                                 visibleloading=1;
2522                                 stillloading=1;
2523                                 Loadlevel(mapname);
2524                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2525                                 //}
2526                                 campaign=1;
2527                                 mainmenu=0;
2528                                 gameon=1;
2529                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2530                         }
2531                         if(Button()&&!oldbutton&&selected==4){
2532                                 float gLoc[3]={0,0,0};
2533                                 float vel[3]={0,0,0};
2534                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2535                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2536                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2537                                 FSOUND_SetVolume(channels[fireendsound], 256);
2538                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2539                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2540
2541                                 flashr=1;
2542                                 flashg=0;
2543                                 flashb=0;
2544                                 flashamount=1;
2545                                 flashdelay=1;
2546
2547                                 if(mainmenu==5&&gameon)mainmenu=2;
2548                                 if(mainmenu==5&&!gameon)mainmenu=1;
2549                         }
2550                         if(Button()&&!oldbutton&&selected==5){
2551                                 float gLoc[3]={0,0,0};
2552                                 float vel[3]={0,0,0};
2553                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2554                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2555                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2556                                 FSOUND_SetVolume(channels[fireendsound], 256);
2557                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2558                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2559
2560                                 flashr=1;
2561                                 flashg=0;
2562                                 flashb=0;
2563                                 flashamount=1;
2564                                 flashdelay=1;
2565
2566                                 mainmenu=7;
2567                         }
2568                         if(Button()&&!oldbutton&&selected==3){
2569                                 float gLoc[3]={0,0,0};
2570                                 float vel[3]={0,0,0};
2571                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2572                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2573                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2574                                 FSOUND_SetVolume(channels[firestartsound], 256);
2575                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2576                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2577
2578                                 flashr=1;
2579                                 flashg=0;
2580                                 flashb=0;
2581                                 flashamount=1;
2582                                 flashdelay=1;
2583
2584                                 mainmenu=6;
2585                         }
2586                         if(Button()&&!oldbutton&&selected==2){
2587                                 float gLoc[3]={0,0,0};
2588                                 float vel[3]={0,0,0};
2589                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2590                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2591                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2592                                 FSOUND_SetVolume(channels[firestartsound], 256);
2593                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2594                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2595
2596                                 flashr=1;
2597                                 flashg=0;
2598                                 flashb=0;
2599                                 flashamount=1;
2600                                 flashdelay=1;
2601
2602                                 mainmenu=9;
2603                         }
2604                         if(Button())oldbutton=1;
2605                         else oldbutton=0;
2606                 }
2607                 if(mainmenu==9){
2608                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){                   
2609                                 float gLoc[3]={0,0,0};
2610                                 float vel[3]={0,0,0};
2611                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2612                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2613                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2614                                 FSOUND_SetVolume(channels[firestartsound], 256);
2615                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2616                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2617
2618                                 flashr=1;
2619                                 flashg=0;
2620                                 flashb=0;
2621                                 flashamount=1;
2622                                 flashdelay=1;
2623
2624                                 startbonustotal=0;
2625
2626                                 loading=2;
2627                                 loadtime=0;
2628                                 targetlevel=selected;
2629                                 if(firstload)TickOnceAfter();
2630                                 if(!firstload)LoadStuff();
2631                                 else {
2632                                         Loadlevel(selected);
2633                                 }
2634                                 campaign=0;
2635
2636                                 mainmenu=0;
2637                                 gameon=1;
2638                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2639                         }
2640                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2641                                 float gLoc[3]={0,0,0};
2642                                 float vel[3]={0,0,0};
2643                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2644                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2645                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2646                                 FSOUND_SetVolume(channels[fireendsound], 256);
2647                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2648                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2649
2650                                 flashr=1;
2651                                 flashg=0;
2652                                 flashb=0;
2653                                 flashamount=1;
2654                                 flashdelay=1;
2655
2656                                 mainmenu=5;
2657                         }
2658                         if(Button())oldbutton=1;
2659                         else oldbutton=0;
2660                 }
2661                 if(mainmenu==11){
2662                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){                   
2663                                 float gLoc[3]={0,0,0};
2664                                 float vel[3]={0,0,0};
2665                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2666                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2667                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2668                                 FSOUND_SetVolume(channels[firestartsound], 256);
2669                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2670                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2671
2672                                 flashr=1;
2673                                 flashg=0;
2674                                 flashb=0;
2675                                 flashamount=1;
2676                                 flashdelay=1;
2677
2678                                 startbonustotal=0;
2679
2680                                 loading=2;
2681                                 loadtime=0;
2682                                 targetlevel=selected;
2683                                 if(firstload)TickOnceAfter();
2684                                 if(!firstload)LoadStuff();
2685                                 else {
2686                                         Loadlevel(selected);
2687                                 }
2688                                 campaign=0;
2689
2690                                 mainmenu=0;
2691                                 gameon=1;
2692                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2693                         }
2694                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2695                                 float gLoc[3]={0,0,0};
2696                                 float vel[3]={0,0,0};
2697                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2698                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2699                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2700                                 FSOUND_SetVolume(channels[fireendsound], 256);
2701                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2702                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2703
2704                                 flashr=1;
2705                                 flashg=0;
2706                                 flashb=0;
2707                                 flashamount=1;
2708                                 flashdelay=1;
2709
2710                                 mainmenu=5;
2711                         }
2712                         if(Button())oldbutton=1;
2713                         else oldbutton=0;
2714                 }
2715                 if(mainmenu==10){
2716                         endgame=2;
2717                         if(Button()&&!oldbutton&&selected==3){
2718                                 float gLoc[3]={0,0,0};
2719                                 float vel[3]={0,0,0};
2720                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2721                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2722                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2723                                 FSOUND_SetVolume(channels[fireendsound], 256);
2724                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2725                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2726
2727                                 flashr=1;
2728                                 flashg=0;
2729                                 flashb=0;
2730                                 flashamount=1;
2731                                 flashdelay=1;
2732
2733                                 mainmenu=5;
2734                         }
2735                         if(Button())oldbutton=1;
2736                         else oldbutton=0;
2737                 }
2738
2739                 if(mainmenu==15||mainmenu==16){
2740                         if(Button()&&!oldbutton&&selected==1){
2741                                 float gLoc[3]={0,0,0};
2742                                 float vel[3]={0,0,0};
2743                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2744                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2745                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2746                                 FSOUND_SetVolume(channels[fireendsound], 256);
2747                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2748                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2749
2750                                 flashr=1;
2751                                 flashg=0;
2752                                 flashb=0;
2753                                 flashamount=1;
2754                                 flashdelay=1;
2755
2756                                 if(mainmenu==15)mainmenu=5;
2757                                 else mainmenu=12;
2758                         }
2759                         if(Button())oldbutton=1;
2760                         else oldbutton=0;
2761                 }
2762
2763                 if(mainmenu==12){
2764                         endgame=2;
2765                         if(Button()&&!oldbutton&&selected==3){
2766                                 if(tryquit)quit=1;
2767                                 float gLoc[3]={0,0,0};
2768                                 float vel[3]={0,0,0};
2769                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2770                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2771                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2772                                 FSOUND_SetVolume(channels[fireendsound], 256);
2773                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2774                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2775
2776                                 flashr=1;
2777                                 flashg=0;
2778                                 flashb=0;
2779                                 flashamount=1;
2780                                 flashdelay=1;
2781
2782                                 mainmenu=5;
2783                         }
2784
2785                         if(Button()&&!oldbutton&&selected==4){
2786                                 registernow=1;
2787                                 quit=1;
2788                                 float gLoc[3]={0,0,0};
2789                                 float vel[3]={0,0,0};
2790                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2791                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2792                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2793                                 FSOUND_SetVolume(channels[fireendsound], 256);
2794                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2795                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2796
2797                                 flashr=1;
2798                                 flashg=0;
2799                                 flashb=0;
2800                                 flashamount=1;
2801                                 flashdelay=1;
2802                         }
2803
2804
2805                         if(Button()&&!oldbutton&&selected==5){
2806                                 tryquit=0;
2807                                 float gLoc[3]={0,0,0};
2808                                 float vel[3]={0,0,0};
2809                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2810                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2811                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2812                                 FSOUND_SetVolume(channels[fireendsound], 256);
2813                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2814                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2815
2816                                 flashr=1;
2817                                 flashg=0;
2818                                 flashb=0;
2819                                 flashamount=1;
2820                                 flashdelay=1;
2821
2822                                 mainmenu=13;
2823                         }
2824                         if(Button())oldbutton=1;
2825                         else oldbutton=0;
2826                 }
2827                 if(mainmenu==6){
2828                         if(Button()&&!oldbutton&&selected!=-1){
2829                                 float gLoc[3]={0,0,0};
2830                                 float vel[3]={0,0,0};
2831                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2832                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2833                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2834                                 FSOUND_SetVolume(channels[firestartsound], 256);
2835                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2836                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2837                         }
2838                         if(Button()&&!oldbutton&&selected==1){
2839                                 float gLoc[3]={0,0,0};
2840                                 float vel[3]={0,0,0};
2841                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2842                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2843                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2844                                 FSOUND_SetVolume(channels[fireendsound], 256);
2845                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2846                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2847
2848                                 flashr=1;
2849                                 flashg=0;
2850                                 flashb=0;
2851                                 flashamount=1;
2852                                 flashdelay=1;
2853
2854                                 for(i=accountactive;i<numaccounts-1;i++){
2855                                         accountdifficulty[i]=accountdifficulty[i+1];
2856                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2857                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2858                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2859                                         }
2860                                         accountpoints[i]=accountpoints[i+1];
2861                                         for(j=0;j<50;j++){
2862                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2863                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2864                                         }
2865                                         for(j=0;j<60;j++){
2866                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2867                                         }
2868                                         for(j=0;j<256;j++){
2869                                                 accountname[i][j]=accountname[i+1][j];
2870                                         }
2871                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2872                                         accountprogress[i]=accountprogress[i+1];
2873                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2874                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2875                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2876                                 }
2877
2878                                 numaccounts--;
2879                                 accountactive=-1;
2880
2881
2882                                 mainmenu=7;
2883                         }
2884                         if(Button()&&!oldbutton&&selected==2){
2885                                 float gLoc[3]={0,0,0};
2886                                 float vel[3]={0,0,0};
2887                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2888                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2889                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2890                                 FSOUND_SetVolume(channels[fireendsound], 256);
2891                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2892                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2893
2894                                 flashr=1;
2895                                 flashg=0;
2896                                 flashb=0;
2897                                 flashamount=1;
2898                                 flashdelay=1;
2899
2900                                 mainmenu=5;
2901                         }
2902                         if(Button())oldbutton=1;
2903                         else oldbutton=0;
2904                 }
2905                 if(mainmenu==7){
2906                         if(Button()&&!oldbutton&&selected!=-1){
2907                                 float gLoc[3]={0,0,0};
2908                                 float vel[3]={0,0,0};
2909                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2910                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2911                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2912                                 FSOUND_SetVolume(channels[firestartsound], 256);
2913                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2914                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2915                         }
2916                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2917                                 entername=1;
2918                         }
2919                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2920                                 accountactive=selected-1;
2921                                 mainmenu=5;
2922                                 flashr=1;
2923                                 flashg=0;
2924                                 flashb=0;
2925                                 flashamount=1;
2926                                 flashdelay=1;
2927                         }
2928                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2929                                 float gLoc[3]={0,0,0};
2930                                 float vel[3]={0,0,0};
2931                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2932                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2933                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2934                                 FSOUND_SetVolume(channels[fireendsound], 256);
2935                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2936                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2937
2938                                 flashr=1;
2939                                 flashg=0;
2940                                 flashb=0;
2941                                 flashamount=1;
2942                                 flashdelay=1;
2943
2944                                 mainmenu=1;
2945
2946                                 for(j=0;j<255;j++){
2947                                         displaytext[0][j]=' ';
2948                                 }
2949                                 displaychars[0]=0;
2950                                 displayselected=0;
2951                                 entername=0;
2952                         }
2953                         if(Button())oldbutton=1;
2954                         else oldbutton=0;
2955                 }
2956                 if(mainmenu==8){
2957                         if(Button()&&!oldbutton&&selected!=-1){
2958                                 float gLoc[3]={0,0,0};
2959                                 float vel[3]={0,0,0};
2960                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2961                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2962                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2963                                 FSOUND_SetVolume(channels[firestartsound], 256);
2964                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2965                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2966
2967                                 if(selected==0)accountdifficulty[accountactive]=0;
2968                                 if(selected==1)accountdifficulty[accountactive]=1;
2969                                 if(selected==2)accountdifficulty[accountactive]=2;
2970
2971                                 mainmenu=5;     
2972
2973                                 flashr=1;
2974                                 flashg=0;
2975                                 flashb=0;
2976                                 flashamount=1;
2977                                 flashdelay=1;
2978
2979                         }
2980                         if(Button())oldbutton=1;
2981                         else oldbutton=0;
2982                 }
2983
2984
2985                 if(Button())oldbutton=1;
2986                 else oldbutton=0;
2987
2988                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
2989                         tryquit=1;
2990                         if(mainmenu==3){
2991                                 if(newdetail>2)newdetail=detail;
2992                                 if(newdetail<0)newdetail=detail;
2993                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2994                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2995                                 if(newscreenheight>3000)newscreenheight=screenheight;
2996                                 if(newscreenheight<0)newscreenheight=screenheight;
2997
2998                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2999                                 opstream << "Screenwidth:\n";
3000                                 opstream << newscreenwidth;
3001                                 opstream << "\nScreenheight:\n";
3002                                 opstream << newscreenheight;
3003                                 opstream << "\nMouse sensitivity:\n";
3004                                 opstream << usermousesensitivity;
3005                                 opstream << "\nBlur(0,1):\n";
3006                                 opstream << ismotionblur;
3007                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
3008                                 opstream << newdetail;
3009                                 opstream << "\nFloating jump:\n";
3010                                 opstream << floatjump;
3011                                 opstream << "\nMouse jump:\n";
3012                                 opstream << mousejump;
3013                                 opstream << "\nAmbient sound:\n";
3014                                 opstream << ambientsound;
3015                                 opstream << "\nBlood (0,1,2):\n";
3016                                 opstream << bloodtoggle;
3017                                 opstream << "\nAuto slomo:\n";
3018                                 opstream << autoslomo;
3019                                 opstream << "\nFoliage:\n";
3020                                 opstream << foliage;
3021                                 opstream << "\nMusic:\n";
3022                                 opstream << musictoggle;
3023                                 opstream << "\nTrilinear:\n";
3024                                 opstream << trilinear;
3025                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
3026                                 opstream << decals;
3027                                 opstream << "\nInvert mouse:\n";
3028                                 opstream << invertmouse;
3029                                 opstream << "\nGamespeed:\n";
3030                                 if(oldgamespeed==0)oldgamespeed=1;
3031                                 opstream << oldgamespeed;
3032                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
3033                                 opstream << difficulty;
3034                                 opstream << "\nDamage effects(blackout, doublevision):\n";
3035                                 opstream << damageeffects;
3036                                 opstream << "\nText:\n";
3037                                 opstream << texttoggle;
3038                                 opstream << "\nDebug:\n";
3039                                 opstream << debugmode;
3040                                 opstream << "\nVBL Sync:\n";
3041                                 opstream << vblsync;
3042                                 opstream << "\nShow Points:\n";
3043                                 opstream << showpoints;
3044                                 opstream << "\nAlways Blur:\n";
3045                                 opstream << alwaysblur;
3046                                 opstream << "\nImmediate mode (turn on on G5):\n";
3047                                 opstream << immediate;
3048                                 opstream << "\nVelocity blur:\n";
3049                                 opstream << velocityblur;
3050                             opstream << "\nVolume:\n";
3051                         opstream << volume;
3052                                 opstream << "\nForward key:\n";
3053                                 opstream << KeyToChar(forwardkey);
3054                                 opstream << "\nBack key:\n";
3055                                 opstream << KeyToChar(backkey);
3056                                 opstream << "\nLeft key:\n";
3057                                 opstream << KeyToChar(leftkey);
3058                                 opstream << "\nRight key:\n";
3059                                 opstream << KeyToChar(rightkey);
3060                                 opstream << "\nJump key:\n";
3061                                 opstream << KeyToChar(jumpkey);
3062                                 opstream << "\nCrouch key:\n";
3063                                 opstream << KeyToChar(crouchkey);
3064                                 opstream << "\nDraw key:\n";
3065                                 opstream << KeyToChar(drawkey);
3066                                 opstream << "\nThrow key:\n";
3067                                 opstream << KeyToChar(throwkey);
3068                                 opstream << "\nAttack key:\n";
3069                                 opstream << KeyToChar(attackkey);
3070                                 opstream << "\nChat key:\n";
3071                                 opstream << KeyToChar(chatkey);
3072                                 opstream.close();
3073                         }
3074                 }
3075
3076                 if(mainmenu==1||mainmenu==2){
3077                         if(loaddistrib>4)transition+=multiplier/8;
3078                         if(transition>1){
3079                                 transition=0;
3080                                 anim++;
3081                                 if(anim>4)anim=0;
3082                                 loaddistrib=0;
3083                         }
3084                 }
3085                 FSOUND_SetFrequency(channels[stream_music3], 22050);            
3086
3087                 if(entername||mainmenu==13||mainmenu==14){
3088                         for(i=0;i<140;i++){
3089                                 if(IsKeyDown(theKeyMap, i)){
3090                                         togglekeydelay[i]+=multiplier;
3091                                         if(togglekeydelay[i]>.4){
3092                                                 togglekey[i]=0;
3093                                                 togglekeydelay[i]=.36;
3094                                         }
3095                                         if(!togglekey[i]){
3096                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3097                                                         for(j=255;j>=displayselected+1;j--){
3098                                                                 displaytext[0][j]=displaytext[0][j-1];
3099                                                         }
3100                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3101                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3102                                                         displayselected++;
3103                                                         displaychars[0]++;
3104                                                 }
3105                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3106                                                         for(j=displayselected-1;j<255;j++){
3107                                                                 displaytext[0][j]=displaytext[0][j+1];
3108                                                         }
3109                                                         displaytext[0][255]=' ';
3110                                                         displayselected--;
3111                                                         displaychars[0]--;
3112                                                 }
3113                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3114                                                         displayselected--;
3115                                                 }
3116                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3117                                                         displayselected++;
3118                                                 }
3119                                                 if(i==MAC_RETURN_KEY&&entername){
3120                                                         if(displaychars[0]){
3121                                                                 numaccounts++;
3122                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
3123                                                                 accountactive=numaccounts-1;
3124                                                                 accountdifficulty[accountactive]=1;
3125                                                                 accountprogress[accountactive]=0;
3126                                                                 accountpoints[accountactive]=0;
3127                                                                 accountcampaigntime[accountactive]=0;
3128                                                                 accountcampaignscore[accountactive]=0;
3129                                                                 accountcampaignfasttime[accountactive]=0;
3130                                                                 accountcampaignhighscore[accountactive]=0;
3131                                                                 for(j=0;j<50;j++){
3132                                                                         accounthighscore[accountactive][j]=0;
3133                                                                         accountfasttime[accountactive][j]=0;
3134                                                                 }
3135                                                                 for(j=0;j<60;j++){
3136                                                                         accountunlocked[accountactive][j]=0;
3137                                                                 }
3138                                                                 accountcampaignchoicesmade[accountactive]=0;
3139
3140                                                                 for(j=0;j<255;j++){
3141                                                                         displaytext[0][j]=' ';
3142                                                                 }
3143                                                                 displaychars[0]=0;
3144                                                                 displayselected=0;
3145                                                                 entername=0;
3146
3147                                                                 mainmenu=8;
3148
3149                                                                 flashr=1;
3150                                                                 flashg=0;
3151                                                                 flashb=0;
3152                                                                 flashamount=1;
3153                                                                 flashdelay=1;
3154
3155                                                                 float gLoc[3]={0,0,0};
3156                                                                 float vel[3]={0,0,0};
3157                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3158                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3159                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3160                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3161                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3162                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3163
3164                                                                 for(j=0;j<255;j++){
3165                                                                         displaytext[0][j]=' ';
3166                                                                 }
3167                                                                 displaychars[0]=0;
3168
3169
3170                                                                 displayselected=0;
3171                                                         }}
3172
3173                                                 if(i==MAC_RETURN_KEY&&mainmenu==14){
3174                                                         if(displaychars[0]){
3175                                                                 char serialstring[256];
3176                                                                 char tempstring[256];
3177                                                                 sprintf (tempstring, "%s-windows", registrationname);
3178                                                                 long num1;
3179                                                                 long num2;
3180                                                                 long num3;
3181                                                                 long num4;
3182                                                                 long long longnum;
3183                                                                 longnum = MD5_string ( tempstring);
3184                                                                 //longnum = 1111111111111111;
3185                                                                 num1 = longnum/100000000;
3186                                                                 num2 = longnum%100000000;
3187                                                                 sprintf (tempstring, "%d-%d-%d-%d\0\0\0\0\0", num1/10000, num1%10000, num2/10000, num2%10000);
3188
3189                                                                 int goodcode=3;
3190                                                                 int numchars=3;
3191                                                                 if(num1/10000>999)numchars+=4;
3192                                                                 else if(num1/10000>99)numchars+=3;
3193                                                                 else if(num1/10000>9)numchars+=2;
3194                                                                 else numchars+=1;
3195                                                                 if(num1%10000>999)numchars+=4;
3196                                                                 else if(num1%10000>99)numchars+=3;
3197                                                                 else if(num1%10000>9)numchars+=2;
3198                                                                 else numchars+=1;
3199                                                                 if(num2/10000>999)numchars+=4;
3200                                                                 else if(num2/10000>99)numchars+=3;
3201                                                                 else if(num2/10000>9)numchars+=2;
3202                                                                 else numchars+=1;
3203                                                                 if(num2%10000>999)numchars+=4;
3204                                                                 else if(num2%10000>99)numchars+=3;
3205                                                                 else if(num2%10000>9)numchars+=2;
3206                                                                 else numchars+=1;
3207
3208                                                                 //numchars=12;
3209
3210                                                                 for(j=0;j<numchars;j++){
3211                                                                         if(displaytext[0][j]!=tempstring[j]&&tempstring[j]!=' '&&tempstring[j]!='\0')goodcode--;
3212                                                                 }
3213
3214                                                                 if(longnum==LONGLONGCONST(5077041556214789))goodcode=-1;
3215
3216                                                                 if(goodcode<0)goodcode=0;
3217
3218                                                                 if(goodcode){
3219                                                                         registered=1;
3220                                                                         mainmenu=15;
3221
3222                                                                         FILE                    *tfile;
3223                                                                         tfile=fopen( ":Data:Sounds:flame.ogg", "wb" );
3224                                                                         if (tfile)
3225                                                                         {
3226                                                                                 int numchars;
3227                                                                                 numchars=strlen(registrationname);
3228                                                                                 fpackf(tfile, "Bb", registered);
3229                                                                                 fpackf(tfile, "Bi", numchars);
3230                                                                                 if(numchars>0)
3231                                                                                 {
3232                                                                                         for(j=0;j<numchars;j++)
3233                                                                                         {
3234                                                                                                 fpackf(tfile, "Bb",  registrationname[j]);
3235                                                                                         }
3236                                                                                 }
3237                                                                                 fpackf(tfile, "Bi", num1);
3238                                                                                 fpackf(tfile, "Bi", num2);
3239                                                                                 fclose(tfile);
3240                                                                         }
3241                                                                 }
3242                                                                 else
3243                                                                 {
3244                                                                         mainmenu=16;
3245                                                                 }
3246                                                                 flashr=1;
3247                                                                 flashg=0;
3248                                                                 flashb=0;
3249                                                                 flashamount=1;
3250                                                                 flashdelay=1;
3251
3252                                                                 float gLoc[3]={0,0,0};
3253                                                                 float vel[3]={0,0,0};
3254                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3255                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3256                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3257                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3258                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3259                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3260
3261                                                                 for(j=0;j<255;j++){
3262                                                                         displaytext[0][j]=' ';
3263                                                                 }
3264                                                                 displaychars[0]=0;
3265                                                                 displayselected=0;
3266                                                         }}
3267
3268                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3269                                                         if(displaychars[0]){
3270                                                                 sprintf (registrationname, "%s", displaytext[0]);
3271                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3272
3273                                                                 mainmenu=14;
3274
3275                                                                 flashr=1;
3276                                                                 flashg=0;
3277                                                                 flashb=0;
3278                                                                 flashamount=1;
3279                                                                 flashdelay=1;
3280
3281                                                                 float gLoc[3]={0,0,0};
3282                                                                 float vel[3]={0,0,0};
3283                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3284                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3285                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3286                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3287                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3288                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3289
3290                                                                 for(j=0;j<255;j++){
3291                                                                         displaytext[0][j]=' ';
3292                                                                 }
3293                                                                 displaychars[0]=0;
3294
3295                                                                 /*char tempstring[50];
3296                                                                 sprintf (tempstring, registrationname);
3297                                                                 long num1;
3298                                                                 long num2;
3299                                                                 long num3;
3300                                                                 long num4;
3301                                                                 long long longnum;
3302                                                                 longnum = MD5_string ( tempstring);
3303                                                                 num1 = longnum/100000000;
3304                                                                 num2 = longnum%100000000;
3305                                                                 sprintf (displaytext[0], "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
3306
3307                                                                 displaychars[0]=strlen(displaytext[0]);
3308                                                                 */
3309                                                                 displayselected=0;
3310                                                         }}
3311                                         }
3312                                         togglekey[i]=1;
3313                                 }
3314                                 else {
3315                                         togglekey[i]=0;
3316                                         togglekeydelay[i]=0;
3317                                 }
3318                         }
3319
3320                         displayblinkdelay-=multiplier;
3321                         if(displayblinkdelay<=0){
3322                                 displayblinkdelay=.3;
3323                                 displayblink=1-displayblink;
3324                         }
3325                 }
3326         }
3327
3328         if(!mainmenu){  
3329                 if(hostile==1)hostiletime+=multiplier;
3330                 else hostiletime=0;
3331                 if(!winfreeze)leveltime+=multiplier;
3332                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3333                         chatting=0;
3334                         console=0;
3335                         freeze=0;
3336                         displaychars[0]=0;
3337                 }
3338
3339                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3340                         chatting=1;
3341                         chattogglekeydown=1;
3342                         togglekey[chatkey]=1;
3343                         togglekeydelay[chatkey]=-20;
3344                 }
3345
3346                 if(!IsKeyDown(theKeyMap, chatkey)){
3347                         chattogglekeydown=0;
3348                 }
3349
3350                 if(chatting){
3351                         for(i=0;i<140;i++){
3352                                 if(IsKeyDown(theKeyMap, i)){
3353                                         togglekeydelay[i]+=multiplier;
3354                                         if(togglekeydelay[i]>.4){
3355                                                 togglekey[i]=0;
3356                                                 togglekeydelay[i]=.36;
3357                                         }
3358                                         if(!togglekey[i]){
3359                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3360                                                         for(j=255;j>=displayselected+1;j--){
3361                                                                 displaytext[0][j]=displaytext[0][j-1];
3362                                                         }
3363                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3364                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3365                                                         displayselected++;
3366                                                         displaychars[0]++;
3367                                                 }
3368                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3369                                                         for(j=displayselected-1;j<255;j++){
3370                                                                 displaytext[0][j]=displaytext[0][j+1];
3371                                                         }
3372                                                         displaytext[0][255]=' ';
3373                                                         displayselected--;
3374                                                         displaychars[0]--;
3375                                                 }
3376                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3377                                                         displayselected--;
3378                                                 }
3379                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3380                                                         displayselected++;
3381                                                 }
3382                                                 if(i==MAC_RETURN_KEY){
3383                                                         if(displaychars[0]){
3384                                                                 /*for(j=0;j<displaychars[0];j++){
3385                                                                 talkname[j]=displaytext[0][j];
3386                                                                 }
3387                                                                 talkname[displaychars[0]]='\0';
3388                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3389                                                                 //NetworkSendInformation(chatname);
3390                                                                 */
3391                                                                 for(j=0;j<255;j++){
3392                                                                         displaytext[0][j]=' ';
3393                                                                 }
3394                                                                 displaychars[0]=0;
3395                                                                 displayselected=0;
3396                                                                 chatting=0;
3397                                                         }
3398                                                 }
3399                                         }
3400                                         togglekey[i]=1;
3401                                 }
3402                                 else {
3403                                         togglekey[i]=0;
3404                                         togglekeydelay[i]=0;
3405                                 }
3406                         }
3407
3408                         displayblinkdelay-=multiplier;
3409                         if(displayblinkdelay<=0){
3410                                 displayblinkdelay=.3;
3411                                 displayblink=1-displayblink;
3412                         }
3413                 }
3414
3415                 if(chatting)keyboardfrozen=1;
3416
3417                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3418                         freeze=1-freeze;
3419                         if(freeze){
3420                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3421                         }
3422                         freezetogglekeydown=1;
3423                 }
3424
3425                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3426                         freezetogglekeydown=0;
3427                 }
3428
3429                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3430                         console=1-console;
3431                         if(!console)freeze=0;
3432                         if(console){
3433                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3434                         }
3435                         consoletogglekeydown=1;
3436                 }
3437
3438                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3439                         consoletogglekeydown=0;
3440                 }
3441
3442                 if(console)freeze=1;
3443
3444                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3445                         for(i=0;i<140;i++){
3446                                 if(IsKeyDown(theKeyMap, i)){
3447                                         togglekeydelay[i]+=multiplier;
3448                                         if(togglekeydelay[i]>.4){
3449                                                 togglekey[i]=0;
3450                                                 togglekeydelay[i]=.36;
3451                                         }
3452                                         if(!togglekey[i]){
3453                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3454                                                         for(j=255;j>=consoleselected+1;j--){
3455                                                                 consoletext[0][j]=consoletext[0][j-1];
3456                                                         }
3457                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3458                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3459                                                         consoleselected++;
3460                                                         consolechars[0]++;
3461                                                 }
3462                                                 else if(i==MAC_ENTER_KEY){
3463                                                         for(j=255;j>=consoleselected+1;j--){
3464                                                                 consoletext[0][j]=consoletext[0][j-1];
3465                                                         }
3466                                                         consoletext[0][consoleselected]='\n';
3467                                                         consoleselected++;
3468                                                         consolechars[0]++;
3469                                                 }
3470                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3471                                                         for(j=consoleselected-1;j<255;j++){
3472                                                                 consoletext[0][j]=consoletext[0][j+1];
3473                                                         }
3474                                                         consoletext[0][255]=' ';
3475                                                         consoleselected--;
3476                                                         consolechars[0]--;
3477                                                 }
3478                                                 if(i==MAC_ARROW_UP_KEY){
3479                                                         if(archiveselected<14)archiveselected++;
3480                                                         for(j=0;j<255;j++){
3481                                                                 consolechars[0]=consolechars[archiveselected];
3482                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3483                                                                 consoleselected=consolechars[0];
3484                                                         }
3485                                                 }
3486                                                 if(i==MAC_ARROW_DOWN_KEY){
3487                                                         if(archiveselected>0)archiveselected--;
3488                                                         for(j=0;j<255;j++){
3489                                                                 consolechars[0]=consolechars[archiveselected];
3490                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3491                                                                 consoleselected=consolechars[0];
3492                                                         }
3493                                                 }
3494                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3495                                                         consoleselected--;
3496                                                 }
3497                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3498                                                         consoleselected++;
3499                                                 }
3500                                                 if(i==MAC_RETURN_KEY){
3501                                                         archiveselected=0;
3502                                                         donesomething=0;
3503                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3504                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3505                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3506                                                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3507                                                                 donesomething=1;
3508                                                                 tryquit=1;
3509                                                         }
3510                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3511                                                         for(j=5;j<consolechars[0];j++){
3512                                                         talkname[j-5]=consoletext[0][j];
3513                                                         }
3514                                                         talkname[consolechars[0]-5]='\0';
3515                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3516                                                         //NetworkSendInformation(chatname);
3517                                                         donesomething=1;
3518                                                         }
3519                                                         if(Compare(consoletext[0],"name ",0,4)){
3520                                                         int numchars;
3521                                                         numchars=consolechars[0]-5;
3522                                                         if(numchars>32)numchars=32;
3523                                                         for(j=5;j<numchars+5;j++){
3524                                                         talkname[j-5]=consoletext[0][j];
3525                                                         }
3526                                                         talkname[numchars]='\0';
3527                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3528                                                         //NetworkSendInformation(chatname);
3529                                                         sprintf (playerName, "%s",talkname);
3530                                                         //NetworkSendName(playerName);
3531                                                         donesomething=1;
3532                                                         }*/
3533                                                         if(Compare(consoletext[0],"map ",0,3)){
3534                                                                 mapname[0]=':';
3535                                                                 mapname[1]='D';
3536                                                                 mapname[2]='a';
3537                                                                 mapname[3]='t';
3538                                                                 mapname[4]='a';
3539                                                                 mapname[5]=':';
3540                                                                 mapname[6]='M';
3541                                                                 mapname[7]='a';
3542                                                                 mapname[8]='p';
3543                                                                 mapname[9]='s';
3544                                                                 mapname[10]=':';
3545                                                                 for(j=4;j<consolechars[0];j++){
3546                                                                         mapname[j-4+11]=consoletext[0][j];
3547                                                                 }
3548                                                                 mapname[consolechars[0]-4+11]='\0';
3549                                                                 Loadlevel(mapname);
3550                                                                 whichlevel=-2;
3551                                                                 campaign=0;
3552                                                                 donesomething=1;
3553                                                         }
3554                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3555                                                         int v;
3556                                                         unsigned char playerNameStr[32];
3557                                                         char theIPAddress[256];
3558                                                         char thePort[32];
3559                                                         NMUInt32 port = 25710;
3560
3561                                                         strcpy(playerName, "Client");
3562                                                         GameC2PStr( playerName, playerNameStr );
3563
3564                                                         for(j=0;j<consolechars[0]-8;j++){
3565                                                         theIPAddress[j]=consoletext[0][j+8];
3566                                                         }
3567                                                         theIPAddress[consolechars[0]-8]='\0';
3568
3569                                                         sprintf( thePort, "%li", port );
3570                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3571                                                         if(v)
3572                                                         {
3573                                                         if(consolechars[0]>0){
3574                                                         for(k=14;k>=1;k--){
3575                                                         for(j=0;j<255;j++){
3576                                                         consoletext[k][j]=consoletext[k-1][j];
3577                                                         }
3578                                                         consolechars[k]=consolechars[k-1];
3579                                                         }
3580                                                         for(j=0;j<255;j++){
3581                                                         consoletext[0][j]=' ';
3582                                                         }
3583                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3584                                                         else sprintf (consoletext[0], "Could not open connection");
3585
3586                                                         consolechars[0]=255;
3587                                                         consoleselected=0;
3588                                                         }
3589                                                         }
3590                                                         else 
3591                                                         {
3592                                                         donesomething=1;
3593                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3594                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3595                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3596
3597                                                         if(consolechars[0]>0){
3598                                                         for(k=14;k>=1;k--){
3599                                                         for(j=0;j<255;j++){
3600                                                         consoletext[k][j]=consoletext[k-1][j];
3601                                                         }
3602                                                         consolechars[k]=consolechars[k-1];
3603                                                         }
3604                                                         for(j=0;j<255;j++){
3605                                                         consoletext[0][j]=' ';
3606                                                         }
3607                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3608
3609                                                         consolechars[0]=255;
3610                                                         consoleselected=0;
3611                                                         }
3612                                                         }
3613                                                         }
3614
3615                                                         if(Compare(consoletext[0],"host ",0,4)){
3616                                                         unsigned char gameNameStr[32], playerNameStr[32];
3617                                                         char gameName[32];//, playerName[32];
3618                                                         NMUInt32 port;
3619                                                         int players;
3620                                                         int v;
3621
3622                                                         port = 25710;
3623                                                         players =4;
3624
3625                                                         strcpy(gameName, "Host's game");
3626                                                         strcpy(playerName, "Host");
3627                                                         GameC2PStr( gameName, gameNameStr );
3628                                                         GameC2PStr( playerName, playerNameStr );
3629
3630                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3631                                                         if(v)
3632                                                         {
3633                                                         if(consolechars[0]>0){
3634                                                         for(k=14;k>=1;k--){
3635                                                         for(j=0;j<255;j++){
3636                                                         consoletext[k][j]=consoletext[k-1][j];
3637                                                         }
3638                                                         consolechars[k]=consolechars[k-1];
3639                                                         }
3640                                                         for(j=0;j<255;j++){
3641                                                         consoletext[0][j]=' ';
3642                                                         }
3643                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3644
3645                                                         consolechars[0]=255;
3646                                                         consoleselected=0;
3647                                                         }
3648                                                         }
3649                                                         else
3650                                                         {
3651                                                         donesomething=1;
3652                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3653                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3654                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3655
3656                                                         if(consolechars[0]>0){
3657                                                         for(k=14;k>=1;k--){
3658                                                         for(j=0;j<255;j++){
3659                                                         consoletext[k][j]=consoletext[k-1][j];
3660                                                         }
3661                                                         consolechars[k]=consolechars[k-1];
3662                                                         }
3663                                                         for(j=0;j<255;j++){
3664                                                         consoletext[0][j]=' ';
3665                                                         }
3666                                                         sprintf (consoletext[0], "Game hosted");
3667
3668                                                         consolechars[0]=255;
3669                                                         consoleselected=0;
3670                                                         }
3671                                                         }
3672                                                         }
3673                                                         */
3674                                                         if(Compare(consoletext[0],"save ",0,4)){
3675                                                                 mapname[0]=':';
3676                                                                 mapname[1]='D';
3677                                                                 mapname[2]='a';
3678                                                                 mapname[3]='t';
3679                                                                 mapname[4]='a';
3680                                                                 mapname[5]=':';
3681                                                                 mapname[6]='M';
3682                                                                 mapname[7]='a';
3683                                                                 mapname[8]='p';
3684                                                                 mapname[9]='s';
3685                                                                 mapname[10]=':';
3686                                                                 for(j=5;j<consolechars[0];j++){
3687                                                                         mapname[j-5+11]=consoletext[0][j];
3688                                                                 }
3689                                                                 mapname[consolechars[0]-5+11]='\0';
3690
3691                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3692                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3693                                                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3694
3695                                                                 int mapvers;
3696                                                                 mapvers=12;
3697
3698
3699                                                                 FILE                    *tfile;
3700                                                                 tfile=fopen( mapname, "wb" );
3701                                                                 fpackf(tfile, "Bi", mapvers);
3702                                                                 //fpackf(tfile, "Bi", indemo);
3703                                                                 fpackf(tfile, "Bi", maptype);
3704                                                                 fpackf(tfile, "Bi", hostile);
3705                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3706                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3707                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3708                                                                 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);
3709                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3710                                                                         for(j=0;j<player[0].num_weapons;j++){
3711                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3712                                                                         }
3713
3714                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3715                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3716                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3717                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3718
3719                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3720
3721                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3722
3723                                                                         fpackf(tfile, "Bi", numdialogues);
3724                                                                         if(numdialogues)
3725                                                                                 for(k=0;k<numdialogues;k++){
3726                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3727                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3728                                                                                         for(l=0;l<10;l++){
3729                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3730                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3731                                                                                         }
3732                                                                                         if(numdialogueboxes)
3733                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3734                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3735                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3736                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3737                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3738                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3739
3740                                                                                                         templength=strlen(dialoguetext[k][l]);
3741                                                                                                         fpackf(tfile, "Bi",(templength));
3742                                                                                                         for(m=0;m<templength;m++){
3743                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3744                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3745                                                                                                         }
3746
3747                                                                                                         templength=strlen(dialoguename[k][l]);
3748                                                                                                         fpackf(tfile, "Bi",templength);
3749                                                                                                         for(m=0;m<templength;m++){
3750                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3751                                                                                                                 if(dialoguename[k][l][m]=='\0')break;   
3752                                                                                                         }
3753
3754                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3755                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3756                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3757
3758                                                                                                         for(m=0;m<10;m++)
3759                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3760
3761                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3762                                                                                                 }
3763                                                                                 }
3764
3765                                                                                 if(player[0].numclothes)
3766                                                                                         for(k=0;k<player[0].numclothes;k++){
3767                                                                                                 templength=strlen(player[0].clothes[k]);
3768                                                                                                 fpackf(tfile, "Bi", templength);
3769                                                                                                 for(l=0;l<templength;l++)
3770                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3771                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);                                                                                                                                             
3772                                                                                         }
3773
3774                                                                                         fpackf(tfile, "Bi", environment);
3775
3776                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3777
3778                                                                                         if(objects.numobjects)
3779                                                                                                 for(k=0;k<objects.numobjects;k++){
3780                                                                                                         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]);
3781                                                                                                 }
3782
3783                                                                                                 fpackf(tfile, "Bi", numhotspots);
3784                                                                                                 if(numhotspots)
3785                                                                                                         for(i=0;i<numhotspots;i++){
3786                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3787                                                                                                                 templength=strlen(hotspottext[i]);
3788                                                                                                                 fpackf(tfile, "Bi",templength);
3789                                                                                                                 for(l=0;l<templength;l++)
3790                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3791                                                                                                         }
3792
3793                                                                                                         fpackf(tfile, "Bi", numplayers);
3794                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3795                                                                                                                 for(j=1;j<numplayers;j++){
3796                                                                                                                         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);
3797                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3798                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3799                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3800                                                                                                                                 }
3801                                                                                                                                 if(player[j].numwaypoints<30){
3802                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3803                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3804                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3805                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3806                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3807                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3808                                                                                                                                         }
3809                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3810                                                                                                                                 }
3811                                                                                                                                 else{
3812                                                                                                                                         player[j].numwaypoints=0;
3813                                                                                                                                         player[j].waypoint=0;
3814                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3815                                                                                                                                 }
3816
3817                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3818                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3819                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3820                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3821
3822                                                                                                                                 if(player[j].creature==wolftype){
3823                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3824                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3825                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3826                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3827                                                                                                                                 }
3828
3829                                                                                                                                 if(player[j].creature==rabbittype){
3830                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3831                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3832                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3833                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3834                                                                                                                                 }
3835
3836                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3837
3838
3839
3840                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3841                                                                                                                                 if(player[j].numclothes)
3842                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3843                                                                                                                                                 int templength;
3844                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3845                                                                                                                                                 fpackf(tfile, "Bi", templength);
3846                                                                                                                                                 for(l=0;l<templength;l++)
3847                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3848                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);                                                                                                                             
3849                                                                                                                                         }
3850                                                                                                                 }
3851
3852                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3853                                                                                                                 if(numpathpoints)
3854                                                                                                                         for(j=0;j<numpathpoints;j++){
3855                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3856                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3857                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3858                                                                                                                                 }
3859                                                                                                                         }
3860
3861                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3862
3863
3864                                                                                                                         fclose(tfile);
3865                                                                                                                         donesomething=1;
3866
3867                                                                                                                         /*
3868                                                                                                                         FILE                    *tfile;
3869                                                                                                                         tfile=fopen( mapname, "wb" );
3870                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3871                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3872                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3873                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3874                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3875                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3876                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3877                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3878                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3879                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3880                                                                                                                         }
3881
3882                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3883                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3884                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3885                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3886                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3887                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3888                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3889                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3890                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3891                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3892                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3893
3894                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3895                                                                                                                         if(player[0].numclothes)
3896                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3897                                                                                                                         int templength;
3898                                                                                                                         templength=strlen(player[0].clothes[k]);
3899                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);       
3900                                                                                                                         for(l=0;l<templength;l++)
3901                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3902                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);      
3903                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);      
3904                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);                                                                              
3905                                                                                                                         }
3906
3907                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3908
3909                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3910
3911                                                                                                                         for(k=0;k<objects.numobjects;k++){
3912                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3913                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3914                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3915                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3916                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3917                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3918                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3919                                                                                                                         }
3920
3921                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3922                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3923                                                                                                                         for(j=1;j<numplayers;j++){
3924                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3925                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3926                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3927                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3928                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3929                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3930                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3931                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3932                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3933                                                                                                                         }
3934                                                                                                                         if(player[j].numwaypoints<30){
3935                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3936                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3937                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3938                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3939                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3940                                                                                                                         }
3941                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3942                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3943                                                                                                                         }
3944                                                                                                                         else{
3945                                                                                                                         player[j].numwaypoints=0;
3946                                                                                                                         player[j].waypoint=0;
3947                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3948                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3949                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3950                                                                                                                         }
3951                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
3952                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
3953                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
3954                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
3955                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
3956                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
3957                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
3958                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
3959                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
3960                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
3961                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
3962
3963                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
3964                                                                                                                         if(player[j].numclothes)
3965                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3966                                                                                                                         int templength;
3967                                                                                                                         templength=strlen(player[j].clothes[k]);
3968                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);       
3969                                                                                                                         for(l=0;l<templength;l++)
3970                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
3971                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);      
3972                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);      
3973                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);                                                                              
3974                                                                                                                         }
3975                                                                                                                         }
3976                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3977                                                                                                                         if(numpathpoints)
3978                                                                                                                         for(j=0;j<numpathpoints;j++){
3979                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
3980                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
3981                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
3982                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3983                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
3984                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3985                                                                                                                         }
3986                                                                                                                         }
3987
3988                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
3989                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
3990                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
3991
3992                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
3993
3994                                                                                                                         fclose(tfile);
3995                                                                                                                         donesomething=1;*/
3996                                                         }
3997                                                         /*
3998                                                         if(Compare(consoletext[0],"save ",0,4)){
3999                                                         mapname[0]=':';
4000                                                         mapname[1]='D';
4001                                                         mapname[2]='a';
4002                                                         mapname[3]='t';
4003                                                         mapname[4]='a';
4004                                                         mapname[5]=':';
4005                                                         mapname[6]='M';
4006                                                         mapname[7]='a';
4007                                                         mapname[8]='p';
4008                                                         mapname[9]='s';
4009                                                         mapname[10]=':';
4010                                                         for(j=5;j<consolechars[0];j++){
4011                                                         mapname[j-5+11]=consoletext[0][j];
4012                                                         }
4013                                                         mapname[consolechars[0]-5+11]='\0';
4014
4015                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
4016                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
4017                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
4018
4019                                                         FILE                    *tfile;
4020                                                         tfile=fopen( mapname, "wb" );
4021                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
4022                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
4023                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
4024                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
4025                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
4026                                                         for(j=0;j<player[0].num_weapons;j++){
4027                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
4028                                                         }
4029                                                         fwrite( &environment, 1, sizeof(int), tfile );
4030
4031                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
4032                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
4033                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
4034                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
4035                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
4036
4037                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4038                                                         if(numplayers>1&&numplayers<maxplayers)
4039                                                         for(j=1;j<numplayers;j++){
4040                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
4041                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4042                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4043                                                         for(k=0;k<player[j].num_weapons;k++){
4044                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4045                                                         }
4046                                                         if(player[j].numwaypoints<30){
4047                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4048                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
4049                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4050                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4051                                                         }
4052                                                         else{
4053                                                         player[j].numwaypoints=0;
4054                                                         player[j].waypoint=0;
4055                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4056                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4057                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4058                                                         }
4059                                                         }
4060                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4061                                                         if(numpathpoints)
4062                                                         for(j=0;j<numpathpoints;j++){
4063                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
4064                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4065                                                         for(k=0;k<numpathpointconnect[j];k++){
4066                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4067                                                         }
4068                                                         }
4069                                                         fclose(tfile);
4070                                                         donesomething=1;
4071                                                         }*/
4072                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
4073                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4074                                                                 donesomething=1;
4075                                                         }
4076                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
4077                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
4078                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
4079                                                         donesomething=1;
4080                                                         }*/
4081
4082                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
4083                                                                 for(j=6;j<consolechars[0];j++){
4084                                                                         mapname[j-6]=consoletext[0][j];
4085                                                                 }
4086
4087                                                                 tintr=atof(mapname);
4088
4089                                                                 donesomething=1;
4090                                                         }
4091
4092                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
4093                                                                 for(j=6;j<consolechars[0];j++){
4094                                                                         mapname[j-6]=consoletext[0][j];
4095                                                                 }
4096
4097                                                                 player[0].speedmult=atof(mapname);
4098
4099                                                                 donesomething=1;
4100                                                         }
4101
4102                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
4103                                                                 for(j=9;j<consolechars[0];j++){
4104                                                                         mapname[j-9]=consoletext[0][j];
4105                                                                 }
4106
4107                                                                 player[0].power=atof(mapname);
4108
4109                                                                 donesomething=1;
4110                                                         }
4111
4112                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
4113                                                                 for(j=13;j<consolechars[0];j++){
4114                                                                         mapname[j-13]=consoletext[0][j];
4115                                                                 }
4116
4117                                                                 viewdistance=atof(mapname)*100;
4118
4119                                                                 donesomething=1;
4120                                                         }
4121
4122                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
4123                                                                 for(j=10;j<consolechars[0];j++){
4124                                                                         mapname[j-10]=consoletext[0][j];
4125                                                                 }
4126
4127                                                                 fadestart=atof(mapname);
4128
4129                                                                 donesomething=1;
4130                                                         }
4131
4132                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
4133                                                                 for(j=6;j<consolechars[0];j++){
4134                                                                         mapname[j-6]=consoletext[0][j];
4135                                                                 }
4136
4137                                                                 player[0].power=atof(mapname);
4138
4139                                                                 donesomething=1;
4140                                                         }
4141
4142                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
4143                                                                 for(j=6;j<consolechars[0];j++){
4144                                                                         mapname[j-6]=consoletext[0][j];
4145                                                                 }
4146
4147                                                                 slomospeed=atof(mapname);
4148                                                                 slomo=1-slomo;
4149                                                                 slomodelay=1000;
4150
4151                                                                 donesomething=1;
4152                                                         }
4153
4154                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
4155                                                                 for(j=8;j<consolechars[0];j++){
4156                                                                         mapname[j-8]=consoletext[0][j];
4157                                                                 }
4158
4159                                                                 slomofreq=atoi(mapname);
4160
4161                                                                 donesomething=1;
4162                                                         }
4163
4164                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
4165                                                                 for(j=5;j<consolechars[0];j++){
4166                                                                         mapname[j-5]=consoletext[0][j];
4167                                                                 }
4168
4169                                                                 player[0].scale=atof(mapname)*.2;
4170
4171                                                                 donesomething=1;
4172                                                         }
4173
4174                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
4175                                                                 int closest=-1;
4176                                                                 float closestdist=-1;
4177                                                                 float distance;
4178                                                                 if(numplayers>1)
4179                                                                         for(i=1;i<numplayers;i++){
4180                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4181                                                                                 if(closestdist==-1||distance<closestdist){
4182                                                                                         closestdist=distance;
4183                                                                                         closest=i;
4184                                                                                 }
4185                                                                         }
4186
4187                                                                         for(j=9;j<consolechars[0];j++){
4188                                                                                 mapname[j-9]=consoletext[0][j];
4189                                                                         }
4190
4191                                                                         player[closest].scale=atof(mapname)*.2;
4192
4193                                                                         donesomething=1;
4194                                                         }
4195
4196                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
4197                                                                 int startpoint;
4198                                                                 int alldone;
4199
4200                                                                 int closest=-1;
4201                                                                 float closestdist=-1;
4202                                                                 float distance;
4203                                                                 if(numplayers>1)
4204                                                                         for(i=1;i<numplayers;i++){
4205                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4206                                                                                 if(closestdist==-1||distance<closestdist){
4207                                                                                         closestdist=distance;
4208                                                                                         closest=i;
4209                                                                                 }
4210                                                                         }
4211
4212                                                                         alldone=0;
4213                                                                         startpoint=15;
4214                                                                         j=startpoint;
4215                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4216                                                                                 mapname[j-startpoint]=consoletext[0][j];
4217                                                                                 j++;
4218                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4219                                                                         }
4220                                                                         mapname[j-startpoint]='\0';
4221
4222                                                                         headprop=atof(mapname);
4223
4224                                                                         j++;
4225                                                                         startpoint=j;
4226                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4227                                                                                 mapname[j-startpoint]=consoletext[0][j];
4228                                                                                 j++;
4229                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4230                                                                         }
4231                                                                         mapname[j-startpoint]='\0';
4232
4233                                                                         bodyprop=atof(mapname);
4234
4235                                                                         j++;
4236                                                                         startpoint=j;
4237                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4238                                                                                 mapname[j-startpoint]=consoletext[0][j];
4239                                                                                 j++;
4240                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4241                                                                         }
4242                                                                         mapname[j-startpoint]='\0';
4243
4244                                                                         armprop=atof(mapname);
4245
4246                                                                         j++;
4247                                                                         startpoint=j;
4248                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4249                                                                                 mapname[j-startpoint]=consoletext[0][j];
4250                                                                                 j++;
4251                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4252                                                                         }
4253                                                                         mapname[j-startpoint]='\0';
4254
4255                                                                         legprop=atof(mapname);
4256
4257                                                                         if(player[closest].creature==wolftype){
4258                                                                                 player[closest].proportionhead=1.1*headprop;
4259                                                                                 player[closest].proportionbody=1.1*bodyprop;
4260                                                                                 player[closest].proportionarms=1.1*armprop;
4261                                                                                 player[closest].proportionlegs=1.1*legprop;
4262                                                                         }
4263
4264                                                                         if(player[closest].creature==rabbittype){
4265                                                                                 player[closest].proportionhead=1.2*headprop;
4266                                                                                 player[closest].proportionbody=1.05*bodyprop;
4267                                                                                 player[closest].proportionarms=1.00*armprop;
4268                                                                                 player[closest].proportionlegs=1.1*legprop;
4269                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4270                                                                         }
4271
4272                                                                         donesomething=1;
4273                                                         }
4274
4275
4276                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4277                                                                 for(i=1;i<numplayers;i++){
4278                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4279                                                                 }
4280
4281                                                                 donesomething=1;
4282                                                         }
4283
4284                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4285                                                                 for(j=9;j<consolechars[0];j++){
4286                                                                         mapname[j-9]=consoletext[0][j];
4287                                                                 }
4288
4289                                                                 tutoriallevel=atoi(mapname);
4290
4291                                                                 donesomething=1;
4292                                                         }
4293
4294
4295                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4296                                                                 for(j=6;j<consolechars[0];j++){
4297                                                                         mapname[j-6]=consoletext[0][j];
4298                                                                 }
4299
4300                                                                 tintg=atof(mapname);
4301
4302                                                                 donesomething=1;
4303                                                         }
4304
4305                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4306                                                                 for(j=6;j<consolechars[0];j++){
4307                                                                         mapname[j-6]=consoletext[0][j];
4308                                                                 }
4309
4310                                                                 tintb=atof(mapname);
4311
4312                                                                 donesomething=1;
4313                                                         }
4314
4315                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4316                                                                 for(j=8;j<consolechars[0];j++){
4317                                                                         mapname[j-8]=consoletext[0][j];
4318                                                                 }
4319
4320                                                                 hostile=atoi(mapname);
4321
4322                                                                 donesomething=1;
4323                                                         }
4324
4325
4326                                                         if(Compare(consoletext[0],"type active ",0,11)){
4327                                                                 editoractive=typeactive;
4328
4329                                                                 donesomething=1;
4330                                                         }
4331
4332                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4333                                                                 indemo=1;
4334                                                                 hotspot[numhotspots]=player[0].coords;
4335                                                                 hotspotsize[numhotspots]=0;
4336                                                                 hotspottype[numhotspots]=-111;
4337                                                                 mapname[0]='\0';
4338                                                                 strcpy(hotspottext[numhotspots],"mapname");
4339                                                                 numhotspots++;
4340
4341                                                                 donesomething=1;
4342                                                         }
4343
4344                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4345                                                                 indemo=0;
4346                                                                 numhotspots--;
4347
4348                                                                 donesomething=1;
4349                                                         }
4350
4351                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4352                                                                 editoractive=typesitting;
4353
4354                                                                 donesomething=1;
4355                                                         }
4356
4357                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4358                                                                 editoractive=typesittingwall;
4359
4360                                                                 donesomething=1;
4361                                                         }
4362
4363                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4364                                                                 editoractive=typesleeping;
4365
4366                                                                 donesomething=1;
4367                                                         }
4368                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4369                                                                 editoractive=typedead1;
4370
4371                                                                 donesomething=1;
4372                                                         }
4373                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4374                                                                 editoractive=typedead2;
4375
4376                                                                 donesomething=1;
4377                                                         }
4378                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4379                                                                 editoractive=typedead3;
4380                                                                 donesomething=1;
4381                                                         }
4382                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4383                                                                 editoractive=typedead4;
4384
4385                                                                 donesomething=1;
4386                                                         }
4387
4388                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4389                                                                 editorpathtype=wpkeepwalking;
4390
4391                                                                 donesomething=1;
4392                                                         }
4393
4394                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4395                                                                 editorpathtype=wppause;
4396
4397                                                                 donesomething=1;
4398                                                         }
4399
4400                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4401                                                                 maptype=mapkilleveryone;
4402
4403                                                                 donesomething=1;
4404                                                         }
4405
4406                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4407                                                                 maptype=mapgosomewhere;
4408
4409                                                                 donesomething=1;
4410                                                         }
4411
4412                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4413                                                                 maptype=mapkillsomeone;
4414
4415                                                                 donesomething=1;
4416
4417                                                         }
4418
4419                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4420                                                                 maptype=mapkillmost;
4421
4422                                                                 donesomething=1;
4423
4424                                                         }
4425
4426                                                         if(Compare(consoletext[0],"hs ",0,2)){
4427                                                                 int startpoint;
4428                                                                 int alldone;
4429
4430                                                                 hotspot[numhotspots]=player[0].coords;
4431
4432                                                                 alldone=0;
4433                                                                 startpoint=3;
4434                                                                 j=startpoint;
4435                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4436                                                                         mapname[j-startpoint]=consoletext[0][j];
4437                                                                         j++;
4438                                                                         if(consoletext[0][j]=='\0')alldone=1;
4439                                                                 }
4440                                                                 mapname[j-startpoint]='\0';
4441
4442                                                                 hotspotsize[numhotspots]=atof(mapname);
4443
4444                                                                 j++;
4445                                                                 startpoint=j;
4446                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4447                                                                         mapname[j-startpoint]=consoletext[0][j];
4448                                                                         j++;
4449                                                                         if(consoletext[0][j]=='\0')alldone=1;
4450                                                                 }
4451                                                                 mapname[j-startpoint]='\0';
4452
4453                                                                 hotspottype[numhotspots]=atoi(mapname);
4454
4455                                                                 j++;
4456                                                                 startpoint=j;
4457                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4458                                                                         mapname[j-startpoint]=consoletext[0][j];
4459                                                                         j++;
4460                                                                         if(consoletext[0][j]=='\0')alldone=1;
4461                                                                 }
4462                                                                 mapname[j-startpoint]='\n';
4463                                                                 mapname[j-startpoint+1]='\0';
4464
4465                                                                 strcpy(hotspottext[numhotspots],mapname);
4466
4467                                                                 numhotspots++;
4468
4469                                                                 donesomething=1;
4470                                                         }
4471
4472                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4473                                                                 int startpoint;
4474                                                                 int alldone;
4475
4476                                                                 alldone=0;
4477                                                                 startpoint=9;
4478                                                                 j=startpoint;
4479                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4480                                                                         mapname[j-startpoint]=consoletext[0][j];
4481                                                                         j++;
4482                                                                         if(consoletext[0][j]=='\0')alldone=1;
4483                                                                 }
4484                                                                 mapname[j-startpoint]='\0';
4485                                                                 startpoint=j+1;
4486
4487                                                                 dialoguetype[numdialogues]=atoi(mapname);
4488
4489                                                                 mapname[0]=':';
4490                                                                 mapname[1]='D';
4491                                                                 mapname[2]='a';
4492                                                                 mapname[3]='t';
4493                                                                 mapname[4]='a';
4494                                                                 mapname[5]=':';
4495                                                                 mapname[6]='D';
4496                                                                 mapname[7]='i';
4497                                                                 mapname[8]='a';
4498                                                                 mapname[9]='l';
4499                                                                 mapname[10]='o';
4500                                                                 mapname[11]='g';
4501                                                                 mapname[12]='u';
4502                                                                 mapname[13]='e';
4503                                                                 mapname[14]='s';
4504                                                                 mapname[15]=':';
4505                                                                 for(j=startpoint;j<consolechars[0];j++){
4506                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4507                                                                 }
4508                                                                 mapname[consolechars[0]-startpoint+16]='.';
4509                                                                 mapname[consolechars[0]-startpoint+17]='t';
4510                                                                 mapname[consolechars[0]-startpoint+18]='x';
4511                                                                 mapname[consolechars[0]-startpoint+19]='t';
4512                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4513
4514                                                                 for(j=0;j<max_dialoguelength;j++){
4515                                                                         for(k=0;k<128;k++){
4516                                                                                 dialoguetext[numdialogues][j][k]='\0';
4517                                                                         }
4518                                                                         for(k=0;k<64;k++){
4519                                                                                 dialoguename[numdialogues][j][k]='\0';
4520                                                                         }
4521                                                                 }
4522
4523                                                                 ifstream ipstream(ConvertFileName(mapname));
4524                                                                 ipstream.ignore(256,':');
4525                                                                 ipstream >> numdialogueboxes[numdialogues];
4526                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4527                                                                         ipstream.ignore(256,':');
4528                                                                         ipstream.ignore(256,':');
4529                                                                         ipstream.ignore(256,' ');
4530                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4531                                                                         ipstream.ignore(256,':');
4532                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4533                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4534                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4535                                                                         ipstream.ignore(256,':');
4536                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4537                                                                         ipstream.ignore(256,':');
4538                                                                         ipstream.ignore(256,' ');
4539                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4540                                                                         for(j=0;j<128;j++){
4541                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4542                                                                         }
4543                                                                         ipstream.ignore(256,':');
4544                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4545                                                                 }
4546
4547                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4548                                                                         for(j=0;j<numplayers;j++){
4549                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4550                                                                         }
4551                                                                 }
4552                                                                 ipstream.close();
4553
4554                                                                 directing=1;
4555                                                                 indialogue=0;
4556                                                                 whichdialogue=numdialogues;
4557
4558
4559                                                                 numdialogues++;
4560
4561                                                                 donesomething=1;
4562                                                         }
4563
4564                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4565                                                                 int startpoint;
4566                                                                 int alldone;
4567                                                                 int whichdi;
4568
4569                                                                 alldone=0;
4570                                                                 startpoint=12;
4571                                                                 j=startpoint;
4572                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4573                                                                         mapname[j-startpoint]=consoletext[0][j];
4574                                                                         j++;
4575                                                                         if(consoletext[0][j]=='\0')alldone=1;
4576                                                                 }
4577                                                                 mapname[j-startpoint]='\0';
4578                                                                 startpoint=j+1;
4579
4580                                                                 whichdi=atoi(mapname);
4581
4582                                                                 mapname[0]=':';
4583                                                                 mapname[1]='D';
4584                                                                 mapname[2]='a';
4585                                                                 mapname[3]='t';
4586                                                                 mapname[4]='a';
4587                                                                 mapname[5]=':';
4588                                                                 mapname[6]='D';
4589                                                                 mapname[7]='i';
4590                                                                 mapname[8]='a';
4591                                                                 mapname[9]='l';
4592                                                                 mapname[10]='o';
4593                                                                 mapname[11]='g';
4594                                                                 mapname[12]='u';
4595                                                                 mapname[13]='e';
4596                                                                 mapname[14]='s';
4597                                                                 mapname[15]=':';
4598                                                                 for(j=startpoint;j<consolechars[0];j++){
4599                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4600                                                                 }
4601                                                                 mapname[consolechars[0]-startpoint+16]='.';
4602                                                                 mapname[consolechars[0]-startpoint+17]='t';
4603                                                                 mapname[consolechars[0]-startpoint+18]='x';
4604                                                                 mapname[consolechars[0]-startpoint+19]='t';
4605                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4606
4607                                                                 for(j=0;j<max_dialoguelength;j++){
4608                                                                         for(k=0;k<128;k++){
4609                                                                                 dialoguetext[whichdi][j][k]='\0';
4610                                                                         }
4611                                                                         for(k=0;k<64;k++){
4612                                                                                 dialoguename[whichdi][j][k]='\0';
4613                                                                         }
4614                                                                 }
4615
4616                                                                 ifstream ipstream(ConvertFileName(mapname));
4617                                                                 ipstream.ignore(256,':');
4618                                                                 ipstream >> numdialogueboxes[whichdi];
4619                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4620                                                                         ipstream.ignore(256,':');
4621                                                                         ipstream.ignore(256,':');
4622                                                                         ipstream.ignore(256,' ');
4623                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4624                                                                         ipstream.ignore(256,':');
4625                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4626                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4627                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4628                                                                         ipstream.ignore(256,':');
4629                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4630                                                                         ipstream.ignore(256,':');
4631                                                                         ipstream.ignore(256,' ');
4632                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4633                                                                         for(j=0;j<128;j++){
4634                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4635                                                                         }
4636                                                                         ipstream.ignore(256,':');
4637                                                                         ipstream >> dialogueboxsound[whichdi][i];
4638                                                                 }
4639
4640                                                                 ipstream.close();
4641
4642                                                                 donesomething=1;
4643                                                         }
4644
4645                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4646                                                                 int startpoint;
4647                                                                 int alldone;
4648                                                                 int whichdi;
4649
4650                                                                 alldone=0;
4651                                                                 startpoint=8;
4652                                                                 j=startpoint;
4653                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4654                                                                         mapname[j-startpoint]=consoletext[0][j];
4655                                                                         j++;
4656                                                                         if(consoletext[0][j]=='\0')alldone=1;
4657                                                                 }
4658                                                                 mapname[j-startpoint]='\0';
4659                                                                 dialoguetype[0]=atoi(mapname);
4660
4661                                                                 startpoint=j+1;
4662
4663                                                                 donesomething=1;
4664                                                         }
4665
4666
4667                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4668                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4669
4670                                                                 donesomething=1;
4671                                                         }
4672
4673                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4674                                                                 numdialogues--;
4675                                                                 if(numdialogues<0)numdialogues=0;
4676
4677                                                                 donesomething=1;
4678                                                         }
4679
4680                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4681                                                                 player[0].immobile=1;
4682                                                                 donesomething=1;
4683                                                         }
4684
4685                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4686                                                                 player[0].immobile=0;
4687                                                                 donesomething=1;
4688                                                         }
4689
4690                                                         if(Compare(consoletext[0],"play ",0,4)){
4691                                                                 int startpoint;
4692                                                                 int alldone;
4693
4694                                                                 alldone=0;
4695                                                                 startpoint=5;
4696                                                                 j=startpoint;
4697                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4698                                                                         mapname[j-startpoint]=consoletext[0][j];
4699                                                                         j++;
4700                                                                         if(consoletext[0][j]=='\0')alldone=1;
4701                                                                 }
4702                                                                 mapname[j-startpoint]='\0';
4703                                                                 startpoint=j+1;
4704
4705                                                                 whichdialogue=atoi(mapname);
4706
4707                                                                 if(numdialogues>whichdialogue){
4708                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4709                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4710                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4711                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4712                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4713                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4714                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4715                                                                         }
4716
4717                                                                         directing=0;
4718                                                                         indialogue=0;
4719
4720                                                                         donesomething=1;
4721
4722                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4723                                                                         float gLoc[3];
4724                                                                         float vel[3];
4725                                                                         XYZ temppos;
4726                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4727                                                                         temppos=temppos-viewer;
4728                                                                         Normalise(&temppos);
4729                                                                         temppos+=viewer;
4730
4731                                                                         gLoc[0]=temppos.x;
4732                                                                         gLoc[1]=temppos.y;
4733                                                                         gLoc[2]=temppos.z;
4734                                                                         vel[0]=0;
4735                                                                         vel[1]=0;
4736                                                                         vel[2]=0;
4737                                                                         int whichsoundplay;
4738                                                                         whichsoundplay=rabbitchitter;
4739                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4740                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4741                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4742                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4743                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4744                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4745                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4746                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4747                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4748                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4749                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4750                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4751                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4752                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4753                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4754                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4755                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4756                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4757                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4758                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
4759                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4760                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
4761                                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
4762                                                                         //}
4763                                                                 }
4764                                                         }
4765
4766
4767
4768
4769                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4770                                                                 numhotspots--;
4771                                                                 if(numhotspots<0)numhotspots=0;
4772                                                                 donesomething=1;
4773                                                         }
4774
4775
4776                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4777                                                                 int startpoint;
4778                                                                 int alldone;
4779
4780                                                                 alldone=0;
4781                                                                 startpoint=11;
4782                                                                 j=startpoint;
4783                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4784                                                                         mapname[j-startpoint]=consoletext[0][j];
4785                                                                         j++;
4786                                                                         if(consoletext[0][j]=='\0')alldone=1;
4787                                                                 }
4788                                                                 mapname[j-startpoint]='\0';
4789
4790                                                                 headprop=atof(mapname);
4791
4792                                                                 j++;
4793                                                                 startpoint=j;
4794                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4795                                                                         mapname[j-startpoint]=consoletext[0][j];
4796                                                                         j++;
4797                                                                         if(consoletext[0][j]=='\0')alldone=1;
4798                                                                 }
4799                                                                 mapname[j-startpoint]='\0';
4800
4801                                                                 bodyprop=atof(mapname);
4802
4803                                                                 j++;
4804                                                                 startpoint=j;
4805                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4806                                                                         mapname[j-startpoint]=consoletext[0][j];
4807                                                                         j++;
4808                                                                         if(consoletext[0][j]=='\0')alldone=1;
4809                                                                 }
4810                                                                 mapname[j-startpoint]='\0';
4811
4812                                                                 armprop=atof(mapname);
4813
4814                                                                 j++;
4815                                                                 startpoint=j;
4816                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4817                                                                         mapname[j-startpoint]=consoletext[0][j];
4818                                                                         j++;
4819                                                                         if(consoletext[0][j]=='\0')alldone=1;
4820                                                                 }
4821                                                                 mapname[j-startpoint]='\0';
4822
4823                                                                 legprop=atof(mapname);
4824
4825                                                                 if(player[0].creature==wolftype){
4826                                                                         player[0].proportionhead=1.1*headprop;
4827                                                                         player[0].proportionbody=1.1*bodyprop;
4828                                                                         player[0].proportionarms=1.1*armprop;
4829                                                                         player[0].proportionlegs=1.1*legprop;
4830                                                                 }
4831
4832                                                                 if(player[0].creature==rabbittype){
4833                                                                         player[0].proportionhead=1.2*headprop;
4834                                                                         player[0].proportionbody=1.05*bodyprop;
4835                                                                         player[0].proportionarms=1.00*armprop;
4836                                                                         player[0].proportionlegs=1.1*legprop;
4837                                                                         player[0].proportionlegs.y=1.05*legprop;
4838                                                                 }
4839
4840                                                                 donesomething=1;
4841                                                         }
4842
4843                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4844                                                                 for(i=0;i<numplayers;i++){
4845                                                                         if(i>0)player[i].immobile=1;
4846                                                                 }
4847                                                                 donesomething=1;
4848                                                         }
4849
4850
4851                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4852                                                                 player[0].armorhead=1;
4853                                                                 player[0].armorhigh=1;
4854                                                                 player[0].armorlow=1;
4855                                                                 player[0].protectionhead=1;
4856                                                                 player[0].protectionhigh=1;
4857                                                                 player[0].protectionlow=1;
4858                                                                 player[0].metalhead=1;
4859                                                                 player[0].metalhigh=1;
4860                                                                 player[0].metallow=1;
4861                                                                 player[0].power=1;
4862                                                                 player[0].speedmult=1;
4863                                                                 player[0].scale=1;
4864
4865                                                                 if(player[0].creature==wolftype){
4866                                                                         player[0].proportionhead=1.1;
4867                                                                         player[0].proportionbody=1.1;
4868                                                                         player[0].proportionarms=1.1;
4869                                                                         player[0].proportionlegs=1.1;
4870                                                                 }
4871
4872                                                                 if(player[0].creature==rabbittype){
4873                                                                         player[0].proportionhead=1.2;
4874                                                                         player[0].proportionbody=1.05;
4875                                                                         player[0].proportionarms=1.00;
4876                                                                         player[0].proportionlegs=1.1;
4877                                                                         player[0].proportionlegs.y=1.05;
4878                                                                 }
4879
4880                                                                 player[0].numclothes=0;
4881                                                                 if(player[0].whichskin==0){
4882                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4883                                                                 }
4884                                                                 else if(player[0].whichskin==1){
4885                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4886                                                                 }
4887                                                                 else if(player[0].whichskin==2){
4888                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4889                                                                 }
4890                                                                 else if(player[0].whichskin==3){
4891                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4892                                                                 }
4893                                                                 else if(player[0].whichskin==4){
4894                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4895                                                                 }
4896                                                                 else if(player[0].whichskin==5){
4897                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4898                                                                 }
4899                                                                 else if(player[0].whichskin==6){
4900                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4901                                                                 }
4902                                                                 else if(player[0].whichskin==7){
4903                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4904                                                                 }
4905                                                                 else if(player[0].whichskin==8){
4906                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4907                                                                 }
4908                                                                 else if(player[0].whichskin==9){
4909                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4910                                                                 }
4911
4912                                                                 editoractive=typeactive;
4913                                                                 player[0].immobile=0;
4914
4915
4916
4917                                                                 donesomething=1;
4918                                                         }
4919
4920                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4921                                                                 int startpoint;
4922                                                                 int alldone;
4923                                                                 alldone=0;
4924                                                                 startpoint=5;
4925                                                                 j=startpoint;
4926                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4927                                                                         mapname[j-startpoint]=consoletext[0][j];
4928                                                                         j++;
4929                                                                         if(consoletext[0][j]=='\0')alldone=1;
4930                                                                 }
4931                                                                 mapname[j-startpoint]='\0';
4932
4933                                                                 tintr=atof(mapname);
4934
4935                                                                 j++;
4936                                                                 startpoint=j;
4937                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4938                                                                         mapname[j-startpoint]=consoletext[0][j];
4939                                                                         j++;
4940                                                                         if(consoletext[0][j]=='\0')alldone=1;
4941                                                                 }
4942                                                                 mapname[j-startpoint]='\0';
4943
4944                                                                 tintg=atof(mapname);
4945
4946                                                                 j++;
4947                                                                 startpoint=j;
4948                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4949                                                                         mapname[j-startpoint]=consoletext[0][j];
4950                                                                         j++;
4951                                                                         if(consoletext[0][j]=='\0')alldone=1;
4952                                                                 }
4953                                                                 mapname[j-startpoint]='\0';
4954
4955                                                                 tintb=atof(mapname);
4956
4957                                                                 donesomething=1;
4958                                                         }
4959
4960                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
4961                                                                 int startpoint;
4962                                                                 int alldone;
4963                                                                 alldone=0;
4964                                                                 startpoint=9;
4965                                                                 j=startpoint;
4966                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4967                                                                         mapname[j-startpoint]=consoletext[0][j];
4968                                                                         j++;
4969                                                                         if(consoletext[0][j]=='\0')alldone=1;
4970                                                                 }
4971                                                                 mapname[j-startpoint]='\0';
4972
4973                                                                 skyboxr=atof(mapname);
4974
4975                                                                 j++;
4976                                                                 startpoint=j;
4977                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4978                                                                         mapname[j-startpoint]=consoletext[0][j];
4979                                                                         j++;
4980                                                                         if(consoletext[0][j]=='\0')alldone=1;
4981                                                                 }
4982                                                                 mapname[j-startpoint]='\0';
4983
4984                                                                 skyboxg=atof(mapname);
4985
4986                                                                 j++;
4987                                                                 startpoint=j;
4988                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4989                                                                         mapname[j-startpoint]=consoletext[0][j];
4990                                                                         j++;
4991                                                                         if(consoletext[0][j]=='\0')alldone=1;
4992                                                                 }
4993                                                                 mapname[j-startpoint]='\0';
4994
4995                                                                 skyboxb=atof(mapname);
4996
4997                                                                 skyboxlightr=skyboxr;
4998                                                                 skyboxlightg=skyboxg;
4999                                                                 skyboxlightb=skyboxb;
5000
5001                                                                 SetUpLighting();
5002
5003                                                                 //if(skyboxtexture){
5004                                                                 terrain.DoShadows();
5005                                                                 objects.DoShadows();
5006                                                                 /*}
5007                                                                 else terrain.DoLighting();
5008                                                                 */
5009                                                                 donesomething=1;
5010                                                         } 
5011
5012                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
5013                                                                 int startpoint;
5014                                                                 int alldone;
5015                                                                 alldone=0;
5016                                                                 startpoint=10;
5017                                                                 j=startpoint;
5018                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5019                                                                         mapname[j-startpoint]=consoletext[0][j];
5020                                                                         j++;
5021                                                                         if(consoletext[0][j]=='\0')alldone=1;
5022                                                                 }
5023                                                                 mapname[j-startpoint]='\0';
5024
5025                                                                 skyboxlightr=atof(mapname);
5026
5027                                                                 j++;
5028                                                                 startpoint=j;
5029                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5030                                                                         mapname[j-startpoint]=consoletext[0][j];
5031                                                                         j++;
5032                                                                         if(consoletext[0][j]=='\0')alldone=1;
5033                                                                 }
5034                                                                 mapname[j-startpoint]='\0';
5035
5036                                                                 skyboxlightg=atof(mapname);
5037
5038                                                                 j++;
5039                                                                 startpoint=j;
5040                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5041                                                                         mapname[j-startpoint]=consoletext[0][j];
5042                                                                         j++;
5043                                                                         if(consoletext[0][j]=='\0')alldone=1;
5044                                                                 }
5045                                                                 mapname[j-startpoint]='\0';
5046
5047                                                                 skyboxlightb=atof(mapname);
5048
5049                                                                 SetUpLighting();
5050
5051                                                                 //if(skyboxtexture){
5052                                                                 terrain.DoShadows();
5053                                                                 objects.DoShadows();
5054                                                                 /*}
5055                                                                 else terrain.DoLighting();
5056                                                                 */
5057                                                                 donesomething=1;
5058                                                         } 
5059
5060                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
5061                                                                 skyboxtexture=1-skyboxtexture;
5062
5063                                                                 SetUpLighting();
5064                                                                 //if(skyboxtexture){
5065                                                                 terrain.DoShadows();
5066                                                                 objects.DoShadows();
5067                                                                 /*}
5068                                                                 else terrain.DoLighting();
5069                                                                 */
5070                                                                 donesomething=1;
5071                                                         }
5072
5073                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
5074                                                                 int startpoint;
5075                                                                 int alldone;
5076                                                                 alldone=0;
5077                                                                 startpoint=11;
5078                                                                 j=startpoint;
5079                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5080                                                                         mapname[j-startpoint]=consoletext[0][j];
5081                                                                         j++;
5082                                                                         if(consoletext[0][j]=='\0')alldone=1;
5083                                                                 }
5084                                                                 mapname[j-startpoint]='\0';
5085
5086                                                                 player[0].protectionhead=atof(mapname);
5087
5088                                                                 j++;
5089                                                                 startpoint=j;
5090                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5091                                                                         mapname[j-startpoint]=consoletext[0][j];
5092                                                                         j++;
5093                                                                         if(consoletext[0][j]=='\0')alldone=1;
5094                                                                 }
5095                                                                 mapname[j-startpoint]='\0';
5096
5097                                                                 player[0].protectionhigh=atof(mapname);
5098
5099                                                                 j++;
5100                                                                 startpoint=j;
5101                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5102                                                                         mapname[j-startpoint]=consoletext[0][j];
5103                                                                         j++;
5104                                                                         if(consoletext[0][j]=='\0')alldone=1;
5105                                                                 }
5106                                                                 mapname[j-startpoint]='\0';
5107
5108                                                                 player[0].protectionlow=atof(mapname);
5109
5110                                                                 donesomething=1;
5111                                                         }
5112
5113                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
5114                                                                 int startpoint;
5115                                                                 int alldone;
5116                                                                 alldone=0;
5117                                                                 startpoint=6;
5118                                                                 j=startpoint;
5119                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5120                                                                         mapname[j-startpoint]=consoletext[0][j];
5121                                                                         j++;
5122                                                                         if(consoletext[0][j]=='\0')alldone=1;
5123                                                                 }
5124                                                                 mapname[j-startpoint]='\0';
5125
5126                                                                 player[0].armorhead=atof(mapname);
5127
5128                                                                 j++;
5129                                                                 startpoint=j;
5130                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5131                                                                         mapname[j-startpoint]=consoletext[0][j];
5132                                                                         j++;
5133                                                                         if(consoletext[0][j]=='\0')alldone=1;
5134                                                                 }
5135                                                                 mapname[j-startpoint]='\0';
5136
5137                                                                 player[0].armorhigh=atof(mapname);
5138
5139                                                                 j++;
5140                                                                 startpoint=j;
5141                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5142                                                                         mapname[j-startpoint]=consoletext[0][j];
5143                                                                         j++;
5144                                                                         if(consoletext[0][j]=='\0')alldone=1;
5145                                                                 }
5146                                                                 mapname[j-startpoint]='\0';
5147
5148                                                                 player[0].armorlow=atof(mapname);
5149
5150                                                                 donesomething=1;
5151                                                         }
5152
5153                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
5154                                                                 for(i=0;i<numplayers;i++){
5155                                                                         player[i].protectionhead=1.0;
5156                                                                         player[i].protectionhigh=1.0;
5157                                                                         player[i].protectionlow=1.0;
5158                                                                         player[i].armorhead=1.0;
5159                                                                         player[i].armorhigh=1.0;
5160                                                                         player[i].armorlow=1.0;
5161                                                                 }
5162
5163                                                                 donesomething=1;
5164                                                         }
5165
5166                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
5167                                                                 int closest=-1;
5168                                                                 float closestdist=-1;
5169                                                                 float distance;
5170                                                                 if(numplayers>1)
5171                                                                         for(i=1;i<numplayers;i++){
5172                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5173                                                                                 if(closestdist==-1||distance<closestdist){
5174                                                                                         closestdist=distance;
5175                                                                                         closest=i;
5176                                                                                 }
5177                                                                         }
5178
5179                                                                         int startpoint;
5180                                                                         int alldone;
5181                                                                         alldone=0;
5182                                                                         startpoint=15;
5183                                                                         j=startpoint;
5184                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5185                                                                                 mapname[j-startpoint]=consoletext[0][j];
5186                                                                                 j++;
5187                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5188                                                                         }
5189                                                                         mapname[j-startpoint]='\0';
5190
5191                                                                         player[closest].protectionhead=atof(mapname);
5192
5193                                                                         j++;
5194                                                                         startpoint=j;
5195                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5196                                                                                 mapname[j-startpoint]=consoletext[0][j];
5197                                                                                 j++;
5198                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5199                                                                         }
5200                                                                         mapname[j-startpoint]='\0';
5201
5202                                                                         player[closest].protectionhigh=atof(mapname);
5203
5204                                                                         j++;
5205                                                                         startpoint=j;
5206                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5207                                                                                 mapname[j-startpoint]=consoletext[0][j];
5208                                                                                 j++;
5209                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5210                                                                         }
5211                                                                         mapname[j-startpoint]='\0';
5212
5213                                                                         player[closest].protectionlow=atof(mapname);
5214
5215                                                                         donesomething=1;
5216                                                         }
5217
5218                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
5219                                                                 int closest=-1;
5220                                                                 float closestdist=-1;
5221                                                                 float distance;
5222                                                                 if(numplayers>1)
5223                                                                         for(i=1;i<numplayers;i++){
5224                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5225                                                                                 if(closestdist==-1||distance<closestdist){
5226                                                                                         closestdist=distance;
5227                                                                                         closest=i;
5228                                                                                 }
5229                                                                         }
5230                                                                         int startpoint;
5231                                                                         int alldone;
5232                                                                         alldone=0;
5233                                                                         startpoint=10;
5234                                                                         j=startpoint;
5235                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5236                                                                                 mapname[j-startpoint]=consoletext[0][j];
5237                                                                                 j++;
5238                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5239                                                                         }
5240                                                                         mapname[j-startpoint]='\0';
5241
5242                                                                         player[closest].armorhead=atof(mapname);
5243
5244                                                                         j++;
5245                                                                         startpoint=j;
5246                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5247                                                                                 mapname[j-startpoint]=consoletext[0][j];
5248                                                                                 j++;
5249                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5250                                                                         }
5251                                                                         mapname[j-startpoint]='\0';
5252
5253                                                                         player[closest].armorhigh=atof(mapname);
5254
5255                                                                         j++;
5256                                                                         startpoint=j;
5257                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5258                                                                                 mapname[j-startpoint]=consoletext[0][j];
5259                                                                                 j++;
5260                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5261                                                                         }
5262                                                                         mapname[j-startpoint]='\0';
5263
5264                                                                         player[closest].armorlow=atof(mapname);
5265
5266                                                                         donesomething=1;
5267                                                         }
5268
5269
5270                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5271                                                                 int startpoint;
5272                                                                 int alldone;
5273                                                                 alldone=0;
5274                                                                 startpoint=6;
5275                                                                 j=startpoint;
5276                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5277                                                                         mapname[j-startpoint]=consoletext[0][j];
5278                                                                         j++;
5279                                                                         if(consoletext[0][j]=='\0')alldone=1;
5280                                                                 }
5281                                                                 mapname[j-startpoint]='\0';
5282
5283                                                                 player[0].metalhead=atof(mapname);
5284
5285                                                                 j++;
5286                                                                 startpoint=j;
5287                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5288                                                                         mapname[j-startpoint]=consoletext[0][j];
5289                                                                         j++;
5290                                                                         if(consoletext[0][j]=='\0')alldone=1;
5291                                                                 }
5292                                                                 mapname[j-startpoint]='\0';
5293
5294                                                                 player[0].metalhigh=atof(mapname);
5295
5296                                                                 j++;
5297                                                                 startpoint=j;
5298                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5299                                                                         mapname[j-startpoint]=consoletext[0][j];
5300                                                                         j++;
5301                                                                         if(consoletext[0][j]=='\0')alldone=1;
5302                                                                 }
5303
5304                                                                 mapname[j-startpoint]='\0';
5305
5306                                                                 player[0].metallow=atof(mapname);
5307
5308                                                                 donesomething=1;
5309                                                         }
5310
5311                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5312                                                                 int closest=-1;
5313                                                                 float closestdist=-1;
5314                                                                 float distance;
5315                                                                 if(numplayers>1)
5316                                                                         for(i=1;i<numplayers;i++){
5317                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5318                                                                                 if(closestdist==-1||distance<closestdist){
5319                                                                                         closestdist=distance;
5320                                                                                         closest=i;
5321                                                                                 }
5322                                                                         }
5323                                                                         player[closest].numclothes=0;
5324                                                                         if(player[closest].whichskin==0){
5325                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5326                                                                         }
5327                                                                         else if(player[closest].whichskin==1){
5328                                                                                 LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5329                                                                         }
5330                                                                         else if(player[closest].whichskin==2){
5331                                                                                 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5332                                                                         }
5333                                                                         else if(player[closest].whichskin==3){
5334                                                                                 LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5335                                                                         }
5336                                                                         else if(player[closest].whichskin==4){
5337                                                                                 LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5338                                                                         }
5339                                                                         else if(player[closest].whichskin==5){
5340                                                                                 LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5341                                                                         }
5342                                                                         else if(player[closest].whichskin==6){
5343                                                                                 LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5344                                                                         }
5345                                                                         else if(player[closest].whichskin==7){
5346                                                                                 LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5347                                                                         }
5348                                                                         else if(player[closest].whichskin==8){
5349                                                                                 LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5350                                                                         }
5351                                                                         else if(player[closest].whichskin==9){
5352                                                                                 LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5353                                                                         }
5354
5355                                                                         donesomething=1;
5356                                                         }
5357
5358                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5359                                                                 int closest=0;
5360
5361                                                                 player[closest].numclothes=0;
5362                                                                 if(player[closest].whichskin==0){
5363                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5364                                                                 }
5365                                                                 else if(player[closest].whichskin==1){
5366                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5367                                                                 }
5368                                                                 else if(player[closest].whichskin==2){
5369                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5370                                                                 }
5371                                                                 else if(player[closest].whichskin==3){
5372                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5373                                                                 }
5374                                                                 else if(player[closest].whichskin==4){
5375                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5376                                                                 }
5377                                                                 else if(player[closest].whichskin==5){
5378                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5379                                                                 }
5380                                                                 else if(player[closest].whichskin==6){
5381                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5382                                                                 }
5383                                                                 else if(player[closest].whichskin==7){
5384                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5385                                                                 }
5386                                                                 else if(player[closest].whichskin==8){
5387                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5388                                                                 }
5389                                                                 else if(player[closest].whichskin==9){
5390                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5391                                                                 }
5392
5393                                                                 donesomething=1;
5394                                                         }
5395
5396                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5397                                                                 mapname[0]=':';
5398                                                                 mapname[1]='D';
5399                                                                 mapname[2]='a';
5400                                                                 mapname[3]='t';
5401                                                                 mapname[4]='a';
5402                                                                 mapname[5]=':';
5403                                                                 mapname[6]='T';
5404                                                                 mapname[7]='e';
5405                                                                 mapname[8]='x';
5406                                                                 mapname[9]='t';
5407                                                                 mapname[10]='u';
5408                                                                 mapname[11]='r';
5409                                                                 mapname[12]='e';
5410                                                                 mapname[13]='s';
5411                                                                 mapname[14]=':';
5412                                                                 for(j=8;j<consolechars[0];j++){
5413                                                                         mapname[j-8+15]=consoletext[0][j];
5414                                                                 }
5415                                                                 mapname[consolechars[0]-8+15]='.';
5416                                                                 mapname[consolechars[0]-8+16]='p';
5417                                                                 mapname[consolechars[0]-8+17]='n';
5418                                                                 mapname[consolechars[0]-8+18]='g';
5419                                                                 mapname[consolechars[0]-8+19]='\0';
5420
5421                                                                 //:Data:Textures:Pants.png
5422
5423                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5424                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5425                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5426                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5427                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5428                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5429                                                                         player[0].numclothes++;
5430                                                                 }
5431
5432                                                                 donesomething=1;
5433                                                         }
5434
5435                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5436                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5437
5438                                                                 donesomething=1;
5439                                                         }
5440
5441                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5442                                                                 cellophane=1-cellophane;
5443
5444                                                                 if(cellophane){
5445                                                                         for(i=0;i<numplayers;i++){
5446                                                                                 player[i].proportionhead.z=0;
5447                                                                                 player[i].proportionbody.z=0;
5448                                                                                 player[i].proportionarms.z=0;
5449                                                                                 player[i].proportionlegs.z=0;
5450                                                                         }
5451                                                                 }
5452
5453                                                                 if(!cellophane){
5454                                                                         for(i=0;i<numplayers;i++){
5455                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5456                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5457                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5458                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5459                                                                         }
5460                                                                 }
5461
5462                                                                 donesomething=1;
5463                                                         }
5464
5465                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5466                                                                 mapname[0]=':';
5467                                                                 mapname[1]='D';
5468                                                                 mapname[2]='a';
5469                                                                 mapname[3]='t';
5470                                                                 mapname[4]='a';
5471                                                                 mapname[5]=':';
5472                                                                 mapname[6]='T';
5473                                                                 mapname[7]='e';
5474                                                                 mapname[8]='x';
5475                                                                 mapname[9]='t';
5476                                                                 mapname[10]='u';
5477                                                                 mapname[11]='r';
5478                                                                 mapname[12]='e';
5479                                                                 mapname[13]='s';
5480                                                                 mapname[14]=':';
5481                                                                 for(j=12;j<consolechars[0];j++){
5482                                                                         mapname[j-12+15]=consoletext[0][j];
5483                                                                 }
5484                                                                 mapname[consolechars[0]-12+15]='.';
5485                                                                 mapname[consolechars[0]-12+16]='p';
5486                                                                 mapname[consolechars[0]-12+17]='n';
5487                                                                 mapname[consolechars[0]-12+18]='g';
5488                                                                 mapname[consolechars[0]-12+19]='\0';
5489
5490                                                                 //:Data:Textures:Pants.png
5491                                                                 int closest=-1;
5492                                                                 float closestdist=-1;
5493                                                                 float distance;
5494                                                                 if(numplayers>1)
5495                                                                         for(i=1;i<numplayers;i++){
5496                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5497                                                                                 if(closestdist==-1||distance<closestdist){
5498                                                                                         closestdist=distance;
5499                                                                                         closest=i;
5500                                                                                 }
5501                                                                         }
5502
5503                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5504                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5505                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5506                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5507                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5508                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5509                                                                                 player[closest].numclothes++;
5510                                                                         }
5511
5512                                                                         donesomething=1;
5513                                                         }
5514
5515                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5516                                                                 player[0].skeleton.id=0;
5517                                                                 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);
5518                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5519                                                                 player[0].creature=rabbittype;
5520                                                                 player[0].scale=.2;
5521
5522                                                                 player[0].proportionhead=1.2;
5523                                                                 player[0].proportionbody=1.05;
5524                                                                 player[0].proportionarms=1.00;
5525                                                                 player[0].proportionlegs=1.1;
5526                                                                 player[0].proportionlegs.y=1.05;
5527                                                                 player[0].headless=0;
5528
5529                                                                 player[0].damagetolerance=200;
5530
5531                                                                 donesomething=1;
5532                                                         }
5533                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5534                                                                 player[0].skeleton.id=0;
5535                                                                 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);
5536                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5537                                                                 player[0].creature=wolftype;
5538
5539                                                                 player[0].proportionhead=1.1;
5540                                                                 player[0].proportionbody=1.1;
5541                                                                 player[0].proportionarms=1.1;
5542                                                                 player[0].proportionlegs=1.1;
5543                                                                 player[0].proportionlegs.y=1.1;
5544                                                                 player[0].scale=.23;
5545
5546                                                                 player[0].damagetolerance=300;
5547
5548                                                                 donesomething=1;
5549                                                         }
5550                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5551                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5552                                                         donesomething=1;
5553                                                         }
5554                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5555                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5556                                                         donesomething=1;
5557                                                         }
5558                                                         if(Compare(consoletext[0],"david ",0,5)){
5559                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5560                                                         donesomething=1;
5561                                                         }*/
5562                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5563                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5564                                                                 donesomething=1;
5565                                                         }
5566                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5567                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5568                                                                 donesomething=1;
5569                                                         }
5570                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5571                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5572                                                                 donesomething=1;
5573                                                         }/*
5574                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5575                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5576                                                          donesomething=1;
5577                                                          }*/
5578                                                         if(Compare(consoletext[0],"white ",0,5)){
5579                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5580                                                                 donesomething=1;
5581                                                         }
5582                                                         if(Compare(consoletext[0],"brown ",0,5)){
5583                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5584                                                                 donesomething=1;
5585                                                         }
5586                                                         if(Compare(consoletext[0],"black ",0,5)){
5587                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5588                                                                 donesomething=1;
5589                                                         }
5590                                                         if(consolechars[0]>0){
5591                                                                 for(k=14;k>=1;k--){
5592                                                                         for(j=0;j<255;j++){
5593                                                                                 consoletext[k][j]=consoletext[k-1][j];
5594                                                                         }
5595                                                                         consolechars[k]=consolechars[k-1];
5596                                                                 }
5597                                                                 for(j=0;j<255;j++){
5598                                                                         consoletext[0][j]=' ';
5599                                                                 }
5600                                                                 consolechars[0]=0;
5601                                                                 consoleselected=0;
5602
5603                                                                 if(!donesomething){
5604                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
5605                                                                         FSOUND_SetVolume(channels[consolefailsound], 256);
5606                                                                         FSOUND_SetPaused(channels[consolefailsound], FALSE);
5607                                                                 }
5608                                                         }
5609                                                 }
5610                                         }
5611                                         togglekey[i]=1;
5612                                 }
5613                                 else {
5614                                         togglekey[i]=0;
5615                                         togglekeydelay[i]=0;
5616                                 }
5617                         }
5618
5619                         consoleblinkdelay-=multiplier;
5620                         if(consoleblinkdelay<=0){
5621                                 consoleblinkdelay=.3;
5622                                 consoleblink=1-consoleblink;
5623                         }
5624                 }
5625
5626                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5627                         tryquit=1;
5628                         if(mainmenu==3){
5629                                 if(newdetail>2)newdetail=detail;
5630                                 if(newdetail<0)newdetail=detail;
5631                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
5632                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5633                                 if(newscreenheight>3000)newscreenheight=screenheight;
5634                                 if(newscreenheight<0)newscreenheight=screenheight;
5635
5636                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5637                                 opstream << "Screenwidth:\n";
5638                                 opstream << newscreenwidth;
5639                                 opstream << "\nScreenheight:\n";
5640                                 opstream << newscreenheight;
5641                                 opstream << "\nMouse sensitivity:\n";
5642                                 opstream << usermousesensitivity;
5643                                 opstream << "\nBlur(0,1):\n";
5644                                 opstream << ismotionblur;
5645                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5646                                 opstream << newdetail;
5647                                 opstream << "\nFloating jump:\n";
5648                                 opstream << floatjump;
5649                                 opstream << "\nMouse jump:\n";
5650                                 opstream << mousejump;
5651                                 opstream << "\nAmbient sound:\n";
5652                                 opstream << ambientsound;
5653                                 opstream << "\nBlood (0,1,2):\n";
5654                                 opstream << bloodtoggle;
5655                                 opstream << "\nAuto slomo:\n";
5656                                 opstream << autoslomo;
5657                                 opstream << "\nFoliage:\n";
5658                                 opstream << foliage;
5659                                 opstream << "\nMusic:\n";
5660                                 opstream << musictoggle;
5661                                 opstream << "\nTrilinear:\n";
5662                                 opstream << trilinear;
5663                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5664                                 opstream << decals;
5665                                 opstream << "\nInvert mouse:\n";
5666                                 opstream << invertmouse;
5667                                 opstream << "\nGamespeed:\n";
5668                                 if(oldgamespeed==0)oldgamespeed=1;
5669                                 opstream << oldgamespeed;
5670                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5671                                 opstream << difficulty;
5672                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5673                                 opstream << damageeffects;
5674                                 opstream << "\nText:\n";
5675                                 opstream << texttoggle;
5676                                 opstream << "\nDebug:\n";
5677                                 opstream << debugmode;
5678                                 opstream << "\nVBL Sync:\n";
5679                                 opstream << vblsync;
5680                                 opstream << "\nShow Points:\n";
5681                                 opstream << showpoints;
5682                                 opstream << "\nAlways Blur:\n";
5683                                 opstream << alwaysblur;
5684                                 opstream << "\nImmediate mode (turn on on G5):\n";
5685                                 opstream << immediate;
5686                                 opstream << "\nVelocity blur:\n";
5687                                 opstream << velocityblur;
5688                             opstream << "\nVolume:\n";
5689                         opstream << volume;
5690                                 opstream << "\nForward key:\n";
5691                                 opstream << KeyToChar(forwardkey);
5692                                 opstream << "\nBack key:\n";
5693                                 opstream << KeyToChar(backkey);
5694                                 opstream << "\nLeft key:\n";
5695                                 opstream << KeyToChar(leftkey);
5696                                 opstream << "\nRight key:\n";
5697                                 opstream << KeyToChar(rightkey);
5698                                 opstream << "\nJump key:\n";
5699                                 opstream << KeyToChar(jumpkey);
5700                                 opstream << "\nCrouch key:\n";
5701                                 opstream << KeyToChar(crouchkey);
5702                                 opstream << "\nDraw key:\n";
5703                                 opstream << KeyToChar(drawkey);
5704                                 opstream << "\nThrow key:\n";
5705                                 opstream << KeyToChar(throwkey);
5706                                 opstream << "\nAttack key:\n";
5707                                 opstream << KeyToChar(attackkey);
5708                                 opstream << "\nChat key:\n";
5709                                 opstream << KeyToChar(chatkey);
5710                                 opstream.close();
5711                         }
5712                 }
5713
5714                 static int oldwinfreeze;
5715                 if(winfreeze&&!oldwinfreeze){
5716                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
5717                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
5718                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
5719                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
5720                 }
5721                 if(winfreeze==0)oldwinfreeze=winfreeze;
5722                 else oldwinfreeze++;
5723
5724                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5725                         if(winfreeze)winfreeze=0;
5726                         oldjumpkeydown=1;
5727                 }
5728                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5729                         if(winfreeze){
5730                                 mainmenu=9;
5731                                 gameon=0;
5732                         }
5733                 }
5734                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5735                         oldjumpkeydown=1;
5736                 }
5737                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5738
5739                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5740
5741                         static bool oldbuttondialogue;
5742
5743                         if(indialogue!=-1)talkdelay=1;
5744                         talkdelay-=multiplier;
5745
5746                         if(talkdelay<=0)
5747                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5748                                         for(i=0;i<numdialogues;i++){
5749                                                 int realdialoguetype;
5750                                                 bool special;
5751                                                 if(dialoguetype[i]>49){
5752                                                         realdialoguetype=dialoguetype[i]-50; 
5753                                                         special=1;
5754                                                 }
5755                                                 else if(dialoguetype[i]>39){
5756                                                         realdialoguetype=dialoguetype[i]-40; 
5757                                                         special=1;
5758                                                 }
5759                                                 else if(dialoguetype[i]>29){
5760                                                         realdialoguetype=dialoguetype[i]-30; 
5761                                                         special=1;
5762                                                 }
5763                                                 else if(dialoguetype[i]>19){
5764                                                         realdialoguetype=dialoguetype[i]-20; 
5765                                                         special=1;
5766                                                 }
5767                                                 else if(dialoguetype[i]>9){
5768                                                         realdialoguetype=dialoguetype[i]-10; 
5769                                                         special=1;
5770                                                 }
5771                                                 else {
5772                                                         realdialoguetype=dialoguetype[i];
5773                                                         special=0;
5774                                                 }
5775                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5776                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5777                                                                 whichdialogue=i;
5778                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5779                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5780                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5781                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5782                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5783                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5784                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5785                                                                 }
5786                                                                 directing=0;
5787                                                                 indialogue=0;
5788                                                                 dialoguetime=0;
5789                                                                 dialoguegonethrough[i]++;
5790                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5791                                                                         static float gLoc[3];
5792                                                                         static float vel[3];
5793                                                                         XYZ temppos;
5794                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5795                                                                         temppos=temppos-viewer;
5796                                                                         Normalise(&temppos);
5797                                                                         temppos+=viewer;
5798
5799                                                                         gLoc[0]=temppos.x;
5800                                                                         gLoc[1]=temppos.y;
5801                                                                         gLoc[2]=temppos.z;vel[0]=0;
5802                                                                         vel[1]=0;
5803                                                                         vel[2]=0;
5804                                                                         int whichsoundplay;
5805                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5806                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5807                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5808                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5809                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5810                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5811                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5812                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5813                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5814                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5815                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5816                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5817                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5818                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5819                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5820                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5821                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5822                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5823                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5824                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5825                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
5826                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5827                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
5828                                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
5829                                                                 }
5830                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5831                                                         }
5832                                                 }
5833                                         }
5834
5835                                         windvar+=multiplier;
5836                                         smoketex+=multiplier;
5837                                         tutorialstagetime+=multiplier;
5838
5839                                         static float hotspotvisual[40];
5840                                         if(numhotspots){
5841                                                 XYZ hotspotsprite;
5842                                                 if(editorenabled)
5843                                                         for(i=0;i<numhotspots;i++)
5844                                                                 hotspotvisual[i]-=multiplier/320;
5845
5846                                                 for(i=0;i<numhotspots;i++){
5847                                                         //if(hotspottype[i]<=10)
5848                                                         while(hotspotvisual[i]<0){
5849                                                                 hotspotsprite=0;
5850                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5851                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5852                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5853                                                                 hotspotsprite+=hotspot[i];
5854                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5855                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5856                                                         }                               
5857                                                 }
5858
5859                                                 for(i=0;i<numhotspots;i++){
5860                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5861                                                                 hotspot[i]=player[hotspottype[i]].coords;
5862                                                         }
5863                                                 }
5864                                         }
5865
5866                                         //Tutorial
5867                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5868                                                 tutorialstage++;
5869                                                 tutorialsuccess=0;
5870                                                 if(tutorialstage<=1){
5871                                                         canattack=0;
5872                                                         cananger=0;
5873                                                         reversaltrain=0;
5874                                                 }
5875                                                 if(tutorialstage==1){
5876                                                         tutorialmaxtime=5;
5877                                                 }
5878                                                 if(tutorialstage==2){
5879                                                         tutorialmaxtime=2;
5880                                                 }
5881                                                 if(tutorialstage==3){
5882                                                         tutorialmaxtime=600;
5883                                                 }
5884                                                 if(tutorialstage==4){
5885                                                         tutorialmaxtime=1000;
5886                                                 }
5887                                                 if(tutorialstage==5){
5888                                                         tutorialmaxtime=600;
5889                                                 }
5890                                                 if(tutorialstage==6){
5891                                                         tutorialmaxtime=600;
5892                                                 }
5893                                                 if(tutorialstage==7){
5894                                                         tutorialmaxtime=600;
5895                                                 }
5896                                                 if(tutorialstage==8){
5897                                                         tutorialmaxtime=600;
5898                                                 }
5899                                                 if(tutorialstage==9){
5900                                                         tutorialmaxtime=600;
5901                                                 }
5902                                                 if(tutorialstage==10){
5903                                                         tutorialmaxtime=2;
5904                                                 }
5905                                                 if(tutorialstage==11){
5906                                                         tutorialmaxtime=1000;
5907                                                 }
5908                                                 if(tutorialstage==12){
5909                                                         tutorialmaxtime=1000;
5910                                                 }
5911                                                 if(tutorialstage==13){
5912                                                         tutorialmaxtime=2;
5913                                                 }
5914                                                 if(tutorialstage==14){
5915                                                         tutorialmaxtime=3;
5916
5917                                                         XYZ temp,temp2;
5918
5919                                                         temp.x=1011;
5920                                                         temp.y=84;
5921                                                         temp.z=491;
5922                                                         temp2.x=1025;
5923                                                         temp2.y=75;
5924                                                         temp2.z=447;
5925
5926                                                         player[1].coords=(temp+temp2)/2;
5927
5928                                                         float gLoc[3];
5929                                                         float vel[3];
5930                                                         gLoc[0]=player[1].coords.x;
5931                                                         gLoc[1]=player[1].coords.y;
5932                                                         gLoc[2]=player[1].coords.z;
5933                                                         vel[0]=0;
5934                                                         vel[1]=0;
5935                                                         vel[2]=0;
5936                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
5937                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5938                                                         FSOUND_SetVolume(channels[fireendsound], 256);
5939                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
5940
5941                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5942                                                                 if(Random()%2==0){
5943                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5944                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5945                                                                         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;
5946                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5947                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5948                                                                 }
5949                                                         }
5950
5951                                                 }
5952                                                 if(tutorialstage==15){
5953                                                         tutorialmaxtime=500;
5954                                                 }
5955                                                 if(tutorialstage==16){
5956                                                         tutorialmaxtime=500;
5957                                                 }
5958                                                 if(tutorialstage==17){
5959                                                         tutorialmaxtime=500;
5960                                                 }
5961                                                 if(tutorialstage==18){
5962                                                         tutorialmaxtime=500;
5963                                                 }
5964                                                 if(tutorialstage==19){
5965                                                         tutorialstage=20;
5966                                                         //tutorialmaxtime=500;
5967                                                 }
5968                                                 if(tutorialstage==20){
5969                                                         tutorialmaxtime=500;
5970                                                 }
5971                                                 if(tutorialstage==21){
5972                                                         tutorialmaxtime=500;
5973                                                         if(bonus==cannon){
5974                                                                 bonus=Slicebonus;
5975                                                                 againbonus=1;
5976                                                         }
5977                                                         else againbonus=0;
5978                                                 }
5979                                                 if(tutorialstage==22){
5980                                                         tutorialmaxtime=500;
5981                                                 }
5982                                                 if(tutorialstage==23){
5983                                                         tutorialmaxtime=500;
5984                                                 }
5985                                                 if(tutorialstage==24){
5986                                                         tutorialmaxtime=500;
5987                                                 }
5988                                                 if(tutorialstage==25){
5989                                                         tutorialmaxtime=500;
5990                                                 }
5991                                                 if(tutorialstage==26){
5992                                                         tutorialmaxtime=2;
5993                                                 }
5994                                                 if(tutorialstage==27){
5995                                                         tutorialmaxtime=4;
5996                                                         reversaltrain=1;
5997                                                         cananger=1;
5998                                                         player[1].aitype=attacktypecutoff;
5999                                                 }
6000                                                 if(tutorialstage==28){
6001                                                         tutorialmaxtime=400;
6002                                                 }
6003                                                 if(tutorialstage==29){
6004                                                         tutorialmaxtime=400;
6005                                                         player[0].escapednum=0;
6006                                                 }
6007                                                 if(tutorialstage==30){
6008                                                         tutorialmaxtime=4;
6009                                                         reversaltrain=0;
6010                                                         cananger=0;
6011                                                         player[1].aitype=passivetype;
6012                                                 }
6013                                                 if(tutorialstage==31){
6014                                                         tutorialmaxtime=13;
6015                                                 }
6016                                                 if(tutorialstage==32){
6017                                                         tutorialmaxtime=8;
6018                                                 }
6019                                                 if(tutorialstage==33){
6020                                                         tutorialmaxtime=400;
6021                                                         cananger=1;
6022                                                         canattack=1;
6023                                                         player[1].aitype=attacktypecutoff;
6024                                                 }
6025                                                 if(tutorialstage==34){
6026                                                         tutorialmaxtime=400;
6027                                                 }
6028                                                 if(tutorialstage==35){
6029                                                         tutorialmaxtime=400;
6030                                                 }
6031                                                 if(tutorialstage==36){
6032                                                         tutorialmaxtime=2;
6033                                                         reversaltrain=0;
6034                                                         cananger=0;
6035                                                         player[1].aitype=passivetype;
6036                                                 }
6037                                                 if(tutorialstage==37){
6038                                                         damagedealt=0;
6039                                                         damagetaken=0;
6040                                                         tutorialmaxtime=50;
6041                                                         cananger=1;
6042                                                         canattack=1;
6043                                                         player[1].aitype=attacktypecutoff;
6044                                                 }
6045                                                 if(tutorialstage==38){
6046                                                         tutorialmaxtime=4;
6047                                                         canattack=0;
6048                                                         cananger=0;
6049                                                         player[1].aitype=passivetype;
6050                                                 }
6051                                                 if(tutorialstage==39){
6052                                                         XYZ temp,temp2;
6053
6054                                                         temp.x=1011;
6055                                                         temp.y=84;
6056                                                         temp.z=491;
6057                                                         temp2.x=1025;
6058                                                         temp2.y=75;
6059                                                         temp2.z=447;
6060
6061
6062                                                         weapons.owner[weapons.numweapons]=-1;
6063                                                         weapons.type[weapons.numweapons]=knife;
6064                                                         weapons.damage[weapons.numweapons]=0;
6065                                                         weapons.mass[weapons.numweapons]=1;
6066                                                         weapons.tipmass[weapons.numweapons]=1.2;
6067                                                         weapons.length[weapons.numweapons]=.25;
6068                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6069                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6070
6071                                                         weapons.velocity[weapons.numweapons]=0.1;
6072                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6073                                                         weapons.missed[weapons.numweapons]=1;
6074                                                         weapons.hitsomething[weapons.numweapons]=0;
6075                                                         weapons.freetime[weapons.numweapons]=0;
6076                                                         weapons.firstfree[weapons.numweapons]=1;
6077                                                         weapons.physics[weapons.numweapons]=1;
6078
6079                                                         weapons.numweapons++;
6080                                                 }
6081                                                 if(tutorialstage==40){
6082                                                         tutorialmaxtime=300;
6083                                                 }
6084                                                 if(tutorialstage==41){
6085                                                         tutorialmaxtime=300;
6086                                                 }
6087                                                 if(tutorialstage==42){
6088                                                         tutorialmaxtime=8;
6089                                                 }
6090                                                 if(tutorialstage==43){
6091                                                         tutorialmaxtime=300;
6092                                                 }
6093                                                 if(tutorialstage==44){
6094                                                         weapons.owner[0]=1;
6095                                                         player[0].weaponactive=-1;
6096                                                         player[0].num_weapons=0;
6097                                                         player[1].weaponactive=0;
6098                                                         player[1].num_weapons=1;
6099                                                         player[1].weaponids[0]=0;
6100
6101                                                         cananger=1;
6102                                                         canattack=1;
6103                                                         player[1].aitype=attacktypecutoff;
6104
6105                                                         tutorialmaxtime=300;
6106                                                 }
6107                                                 if(tutorialstage==45){
6108                                                         weapons.owner[0]=1;
6109                                                         player[0].weaponactive=-1;
6110                                                         player[0].num_weapons=0;
6111                                                         player[1].weaponactive=0;
6112                                                         player[1].num_weapons=1;
6113                                                         player[1].weaponids[0]=0;
6114
6115                                                         tutorialmaxtime=300;
6116                                                 }
6117                                                 if(tutorialstage==46){
6118                                                         weapons.owner[0]=1;
6119                                                         player[0].weaponactive=-1;
6120                                                         player[0].num_weapons=0;
6121                                                         player[1].weaponactive=0;
6122                                                         player[1].num_weapons=1;
6123                                                         player[1].weaponids[0]=0;
6124
6125                                                         weapons.type[0]=sword;
6126
6127                                                         tutorialmaxtime=300;
6128                                                 }
6129
6130                                                 if(tutorialstage==47){
6131                                                         tutorialmaxtime=10;
6132
6133                                                         XYZ temp,temp2;
6134
6135                                                         temp.x=1011;
6136                                                         temp.y=84;
6137                                                         temp.z=491;
6138                                                         temp2.x=1025;
6139                                                         temp2.y=75;
6140                                                         temp2.z=447;
6141
6142                                                         weapons.owner[weapons.numweapons]=-1;
6143                                                         weapons.type[weapons.numweapons]=sword;
6144                                                         weapons.damage[weapons.numweapons]=0;
6145                                                         weapons.mass[weapons.numweapons]=1;
6146                                                         weapons.tipmass[weapons.numweapons]=1.2;
6147                                                         weapons.length[weapons.numweapons]=.25;
6148                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6149                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6150
6151                                                         weapons.velocity[weapons.numweapons]=0.1;
6152                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6153                                                         weapons.missed[weapons.numweapons]=1;
6154                                                         weapons.hitsomething[weapons.numweapons]=0;
6155                                                         weapons.freetime[weapons.numweapons]=0;
6156                                                         weapons.firstfree[weapons.numweapons]=1;
6157                                                         weapons.physics[weapons.numweapons]=1;
6158
6159                                                         weapons.owner[0]=1;
6160                                                         weapons.owner[1]=0;
6161                                                         player[0].weaponactive=0;
6162                                                         player[0].num_weapons=1;
6163                                                         player[0].weaponids[0]=1;       
6164                                                         player[1].weaponactive=0;
6165                                                         player[1].num_weapons=1;
6166                                                         player[1].weaponids[0]=0;       
6167
6168                                                         weapons.numweapons++;
6169                                                 }
6170                                                 if(tutorialstage==48){
6171                                                         canattack=0;
6172                                                         cananger=0;
6173                                                         player[1].aitype=passivetype;
6174
6175                                                         tutorialmaxtime=15;
6176
6177                                                         weapons.owner[0]=1;
6178                                                         weapons.owner[1]=0;
6179                                                         player[0].weaponactive=0;
6180                                                         player[0].num_weapons=1;
6181                                                         player[0].weaponids[0]=1;       
6182                                                         player[1].weaponactive=0;
6183                                                         player[1].num_weapons=1;
6184                                                         player[1].weaponids[0]=0;
6185
6186                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
6187                                                         else weapons.type[0]=staff;
6188
6189                                                         weapons.numweapons++;
6190                                                 }
6191                                                 if(tutorialstage==49){
6192                                                         canattack=0;
6193                                                         cananger=0;
6194                                                         player[1].aitype=passivetype;
6195
6196                                                         tutorialmaxtime=200;
6197
6198                                                         weapons.position[1]=1000;
6199                                                         weapons.tippoint[1]=1000;
6200
6201                                                         weapons.numweapons=1;
6202                                                         weapons.owner[0]=0;
6203                                                         player[1].weaponactive=-1;
6204                                                         player[1].num_weapons=0;
6205                                                         player[0].weaponactive=0;
6206                                                         player[0].num_weapons=1;
6207                                                         player[0].weaponids[0]=0;       
6208
6209                                                         weapons.type[0]=knife;
6210
6211                                                         weapons.numweapons++;
6212                                                 }
6213                                                 if(tutorialstage==50){
6214                                                         tutorialmaxtime=8;
6215
6216                                                         XYZ temp,temp2;
6217                                                         float gLoc[3];
6218                                                         float vel[3];
6219                                                         gLoc[0]=player[1].coords.x;
6220                                                         gLoc[1]=player[1].coords.y;
6221                                                         gLoc[2]=player[1].coords.z;
6222                                                         vel[0]=0;
6223                                                         vel[1]=0;
6224                                                         vel[2]=0;
6225                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
6226                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6227                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6228                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6229
6230                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6231                                                                 if(Random()%2==0){
6232                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6233                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6234                                                                         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;
6235                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6236                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6237                                                                 }
6238                                                         }
6239
6240                                                         player[1].num_weapons=0;
6241                                                         player[1].weaponstuck=-1;
6242                                                         player[1].weaponactive=-1;
6243
6244                                                         weapons.numweapons=0;
6245
6246                                                         weapons.owner[0]=-1;
6247                                                         weapons.velocity[0]=0.1;
6248                                                         weapons.tipvelocity[0]=-0.1;
6249                                                         weapons.missed[0]=1;
6250                                                         weapons.hitsomething[0]=0;
6251                                                         weapons.freetime[0]=0;
6252                                                         weapons.firstfree[0]=1;
6253                                                         weapons.physics[0]=1;
6254                                                 }
6255                                                 if(tutorialstage==51){
6256                                                         tutorialmaxtime=80000;
6257                                                 }
6258                                                 if(tutorialstage<=51)tutorialstagetime=0;
6259                                         }
6260
6261                                         //Tutorial success
6262                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6263                                                 if(tutorialstage==3){
6264                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6265                                                 }
6266                                                 if(tutorialstage==4){
6267                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6268                                                 }
6269                                                 if(tutorialstage==5){
6270                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6271                                                 }
6272                                                 if(tutorialstage==6){
6273                                                         if(player[0].isCrouch())tutorialsuccess=1;
6274                                                 }
6275                                                 if(tutorialstage==7){
6276                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6277                                                 }
6278                                                 if(tutorialstage==8){
6279                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6280                                                 }
6281                                                 if(tutorialstage==9){
6282                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6283                                                 }
6284                                                 if(tutorialstage==11){
6285                                                         if(player[0].isWallJump())tutorialsuccess=1;
6286                                                 }
6287                                                 if(tutorialstage==12){
6288                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6289                                                 }
6290                                                 if(tutorialstage==15){
6291                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6292                                                 }
6293                                                 if(tutorialstage==16){
6294                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6295                                                 }
6296                                                 if(tutorialstage==17){
6297                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6298                                                 }
6299                                                 if(tutorialstage==18){
6300                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6301                                                 }
6302                                                 if(tutorialstage==19){
6303                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6304                                                 }
6305                                                 if(tutorialstage==20){
6306                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6307                                                 }
6308                                                 if(tutorialstage==21){
6309                                                         if(bonus==cannon)tutorialsuccess=1;
6310                                                 }
6311                                                 if(tutorialstage==22){
6312                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6313                                                 }
6314                                                 if(tutorialstage==23){
6315                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6316                                                 }
6317                                                 if(tutorialstage==24){
6318                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6319                                                 }
6320                                                 if(tutorialstage==25){
6321                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6322                                                 }
6323                                                 if(tutorialstage==28){
6324                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6325                                                 }
6326                                                 if(tutorialstage==29){
6327                                                         if(player[0].escapednum==2){
6328                                                                 tutorialsuccess=1;
6329                                                                 reversaltrain=0;
6330                                                                 cananger=0;
6331                                                                 player[1].aitype=passivetype;
6332                                                         }
6333                                                 }
6334                                                 if(tutorialstage==33){
6335                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6336                                                 }
6337                                                 if(tutorialstage==34){
6338                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6339                                                 }
6340                                                 if(tutorialstage==35){
6341                                                         if(animation[player[0].targetanimation].attack==reversal){
6342                                                                 tutorialsuccess=1;
6343                                                                 reversaltrain=0;
6344                                                                 cananger=0;
6345                                                                 player[1].aitype=passivetype;
6346                                                         }
6347                                                 }
6348                                                 if(tutorialstage==40){
6349                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6350                                                 }
6351                                                 if(tutorialstage==41){
6352                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6353                                                 }
6354                                                 if(tutorialstage==43){
6355                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6356                                                 }
6357                                                 if(tutorialstage==44){
6358                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6359                                                 }
6360                                                 if(tutorialstage==45){
6361                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6362                                                 }
6363                                                 if(tutorialstage==46){
6364                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6365                                                 }
6366                                                 if(tutorialstage==49){
6367                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6368                                                 }
6369                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6370
6371
6372                                                 if(tutorialstagetime==tutorialmaxtime-3){
6373                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
6374                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6375                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
6376                                                 }
6377
6378                                                 if(tutorialsuccess>=1){
6379                                                         if(tutorialstage==34||tutorialstage==35)
6380                                                                 tutorialstagetime=tutorialmaxtime-1;
6381                                                 }
6382                                         }
6383
6384                                         if(tutoriallevel){
6385                                                 if(tutorialstage<14||tutorialstage>=50){
6386                                                         player[1].coords.y=300;
6387                                                         player[1].velocity=0;
6388                                                 }
6389                                         }
6390
6391                                         if(tutoriallevel!=1){
6392                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6393                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
6394                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6395                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
6396                                                 }
6397                                         }
6398                                         else
6399                                                 if(bonustime==0){
6400                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
6401                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6402                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6403                                                 }
6404                                                 if(bonustime==0){
6405                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6406                                                         else bonusnum[bonus]+=0.15;
6407                                                         if(tutoriallevel)bonusvalue=0;
6408                                                         bonusvalue/=bonusnum[bonus];
6409                                                         bonustotal+=bonusvalue;
6410                                                 }
6411                                                 bonustime+=multiplier;
6412
6413                                                 if(environment==snowyenvironment){
6414                                                         precipdelay-=multiplier;
6415                                                         while(precipdelay<0){
6416                                                                 precipdelay+=.04;
6417                                                                 if(!detail)precipdelay+=.04;
6418                                                                 XYZ footvel,footpoint;
6419
6420                                                                 footvel=0;
6421                                                                 footpoint=viewer+viewerfacing*6;
6422                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6423                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6424                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6425                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6426                                                         }
6427                                                 }
6428                                                 for(k=0;k<numplayers;k++){
6429                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6430                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6431
6432                                                         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){
6433                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6434                                                                 else if(player[k].rotation>player[k].targetrotation){
6435                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6436                                                                 }
6437                                                                 else if(player[k].rotation<player[k].targetrotation){
6438                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6439                                                                 }
6440                                                         }
6441
6442
6443                                                         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))){
6444                                                                 player[k].turnspeed*=2;
6445                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6446                                                                 else if(player[k].rotation>player[k].targetrotation){
6447                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6448                                                                 }
6449                                                                 else if(player[k].rotation<player[k].targetrotation){
6450                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6451                                                                 }
6452                                                                 player[k].turnspeed/=2;
6453                                                         }
6454
6455                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6456                                                                 player[k].turnspeed*=4;
6457                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6458                                                                 else if(player[k].rotation>player[k].targetrotation){
6459                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6460                                                                 }
6461                                                                 else if(player[k].rotation<player[k].targetrotation){
6462                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6463                                                                 }
6464                                                                 player[k].turnspeed/=4;
6465                                                         }
6466
6467                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6468                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6469
6470                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6471                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6472                                                                         bool tempcollide=0;
6473
6474                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6475                                                                         if(player[k].collide>1)player[k].collide=1;
6476                                                                         player[k].collide-=multiplier*30;
6477
6478                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6479                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6480                                                                         }
6481                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6482                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6483                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6484                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6485                                                                                                 lowpoint=player[k].coords;
6486                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6487                                                                                                 else lowpoint.y+=1.3;
6488                                                                                                 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){
6489                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6490                                                                                                 }
6491                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6492                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6493                                                                                                 */
6494                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6495                                                                                                         flatfacing=lowpoint-player[k].coords;
6496                                                                                                         player[k].coords=lowpoint;
6497                                                                                                         player[k].coords.y-=1.3;
6498                                                                                                         player[k].collide=1;
6499                                                                                                         tempcollide=1;
6500                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6501                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6502                                                                                                                 tempcoords1=lowpoint;
6503                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6504                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6505                                                                                                                         player[k].target=0;
6506                                                                                                                         player[k].targetanimation=walljumpleftanim;
6507                                                                                                                         player[k].targetframe=0;
6508                                                                                                                         float gLoc[3];
6509                                                                                                                         float vel[3];
6510                                                                                                                         gLoc[0]=player[k].coords.x;
6511                                                                                                                         gLoc[1]=player[k].coords.y;
6512                                                                                                                         gLoc[2]=player[k].coords.z;
6513                                                                                                                         vel[0]=0;
6514                                                                                                                         vel[1]=0;
6515                                                                                                                         vel[2]=0;
6516                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6517                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6518                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6519                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6520                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6521
6522                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6523                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6524                                                                                                                         player[k].rotation*=360/6.28;
6525                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6526                                                                                                                         player[k].targetrotation=player[k].rotation;
6527                                                                                                                         player[k].lowrotation=player[k].rotation;
6528                                                                                                                         if(k==0)numwallflipped++;
6529                                                                                                                 }
6530                                                                                                                 else
6531                                                                                                                 {
6532                                                                                                                         lowpoint=tempcoords1;
6533                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6534                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6535                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6536                                                                                                                                 player[k].target=0;
6537                                                                                                                                 player[k].targetanimation=walljumprightanim;
6538                                                                                                                                 player[k].targetframe=0;
6539                                                                                                                                 float gLoc[3];
6540                                                                                                                                 float vel[3];
6541                                                                                                                                 gLoc[0]=player[k].coords.x;
6542                                                                                                                                 gLoc[1]=player[k].coords.y;
6543                                                                                                                                 gLoc[2]=player[k].coords.z;
6544                                                                                                                                 vel[0]=0;
6545                                                                                                                                 vel[1]=0;
6546                                                                                                                                 vel[2]=0;
6547                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6548                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6549                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6550                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6551                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6552
6553                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6554                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6555                                                                                                                                 player[k].rotation*=360/6.28;
6556                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6557                                                                                                                                 player[k].targetrotation=player[k].rotation;
6558                                                                                                                                 player[k].lowrotation=player[k].rotation;
6559                                                                                                                                 if(k==0)numwallflipped++;
6560                                                                                                                         }
6561                                                                                                                         else
6562                                                                                                                         {
6563                                                                                                                                 lowpoint=tempcoords1;
6564                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6565                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6566                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6567                                                                                                                                         player[k].target=0;
6568                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6569                                                                                                                                         player[k].targetframe=0;
6570                                                                                                                                         float gLoc[3];
6571                                                                                                                                         float vel[3];
6572                                                                                                                                         gLoc[0]=player[k].coords.x;
6573                                                                                                                                         gLoc[1]=player[k].coords.y;
6574                                                                                                                                         gLoc[2]=player[k].coords.z;
6575                                                                                                                                         vel[0]=0;
6576                                                                                                                                         vel[1]=0;
6577                                                                                                                                         vel[2]=0;
6578                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6579                                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6580                                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6581                                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6582                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6583
6584                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6585                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6586                                                                                                                                         player[k].rotation*=360/6.28;
6587                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6588                                                                                                                                         player[k].targetrotation=player[k].rotation;
6589                                                                                                                                         player[k].lowrotation=player[k].rotation;
6590                                                                                                                                         if(k==0)numwallflipped++;
6591                                                                                                                                 }
6592                                                                                                                                 else
6593                                                                                                                                 {
6594                                                                                                                                         lowpoint=tempcoords1;
6595                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6596                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6597                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6598                                                                                                                                                 player[k].target=0;
6599                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6600                                                                                                                                                 player[k].targetframe=0;
6601                                                                                                                                                 float gLoc[3];
6602                                                                                                                                                 float vel[3];
6603                                                                                                                                                 gLoc[0]=player[k].coords.x;
6604                                                                                                                                                 gLoc[1]=player[k].coords.y;
6605                                                                                                                                                 gLoc[2]=player[k].coords.z;
6606                                                                                                                                                 vel[0]=0;
6607                                                                                                                                                 vel[1]=0;
6608                                                                                                                                                 vel[2]=0;
6609                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6610                                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6611                                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6612                                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6613                                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6614
6615                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6616                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6617                                                                                                                                                 player[k].rotation*=360/6.28;
6618                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6619                                                                                                                                                 player[k].rotation+=180;
6620                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6621                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6622                                                                                                                                                 if(k==0)numwallflipped++;
6623                                                                                                                                         }
6624                                                                                                                                 }
6625                                                                                                                         }
6626                                                                                                                 }
6627                                                                                                         }
6628                                                                                                 }
6629                                                                                         }
6630                                                                                         else if(objects.type[i]==rocktype){
6631                                                                                                 lowpoint2=player[k].coords;
6632                                                                                                 lowpoint=player[k].coords;
6633                                                                                                 lowpoint.y+=2;
6634                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6635                                                                                                         player[k].coords=colpoint;
6636                                                                                                         player[k].collide=1;
6637                                                                                                         tempcollide=1;
6638
6639                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6640                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6641
6642                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6643                                                                                                                 player[k].target=0;
6644                                                                                                                 player[k].targetframe=0;        
6645                                                                                                                 player[k].onterrain=1;
6646
6647                                                                                                                 if(player[k].id==0){
6648                                                                                                                         FSOUND_SetPaused(channels[whooshsound], TRUE);
6649                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 0);
6650                                                                                                                 }
6651
6652                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6653                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6654                                                                                                                         player[k].targetanimation=player[k].getLanding();
6655                                                                                                                         float gLoc[3];
6656                                                                                                                         float vel[3];
6657                                                                                                                         gLoc[0]=player[k].coords.x;
6658                                                                                                                         gLoc[1]=player[k].coords.y;
6659                                                                                                                         gLoc[2]=player[k].coords.z;
6660                                                                                                                         vel[0]=player[k].velocity.x;
6661                                                                                                                         vel[1]=player[k].velocity.y;
6662                                                                                                                         vel[2]=player[k].velocity.z;
6663                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, TRUE);
6664                                                                                                                         FSOUND_3D_SetAttributes(channels[landsound], gLoc, vel);
6665                                                                                                                         FSOUND_SetVolume(channels[landsound], 128);
6666                                                                                                                         FSOUND_SetPaused(channels[landsound], FALSE);
6667                                                                                                                         if(k==0){
6668                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6669                                                                                                                                 envsoundvol[numenvsounds]=16;
6670                                                                                                                                 envsoundlife[numenvsounds]=.4;
6671                                                                                                                                 numenvsounds++;
6672                                                                                                                         }
6673
6674                                                                                                                 }
6675                                                                                                         }
6676                                                                                                 }                               
6677                                                                                         }
6678                                                                                 }
6679                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6680                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6681                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6682                                                                                                 lowpoint=player[k].coords;
6683                                                                                                 lowpoint.y+=1.35;
6684                                                                                                 if(objects.type[i]!=rocktype)
6685                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6686                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;               
6687                                                                                                                 player[k].coords=lowpoint;
6688                                                                                                                 player[k].coords.y-=1.35;
6689                                                                                                                 player[k].collide=1;    
6690
6691                                                                                                                 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)){
6692                                                                                                                         lowpoint=player[k].coords;
6693                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6694                                                                                                                         lowpoint=player[k].coords;
6695                                                                                                                         lowpoint.y+=.05;
6696                                                                                                                         facing=0;
6697                                                                                                                         facing.z=-1;
6698                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6699                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6700                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6701                                                                                                                         if(whichhit!=-1){
6702                                                                                                                                 lowpoint=player[k].coords;
6703                                                                                                                                 lowpoint.y+=.1;
6704                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6705                                                                                                                                 lowpoint2=lowpoint;
6706                                                                                                                                 lowpointtarget2=lowpointtarget;
6707                                                                                                                                 lowpoint3=lowpoint;
6708                                                                                                                                 lowpointtarget3=lowpointtarget;
6709                                                                                                                                 lowpoint4=lowpoint;
6710                                                                                                                                 lowpointtarget4=lowpointtarget;
6711                                                                                                                                 lowpoint5=lowpoint;
6712                                                                                                                                 lowpointtarget5=lowpointtarget;
6713                                                                                                                                 lowpoint6=lowpoint;
6714                                                                                                                                 lowpointtarget6=lowpointtarget;
6715                                                                                                                                 lowpoint7=lowpoint;
6716                                                                                                                                 lowpointtarget7=lowpoint;
6717                                                                                                                                 lowpoint2.x+=.1;
6718                                                                                                                                 lowpointtarget2.x+=.1;
6719                                                                                                                                 lowpoint3.z+=.1;
6720                                                                                                                                 lowpointtarget3.z+=.1;
6721                                                                                                                                 lowpoint4.x-=.1;
6722                                                                                                                                 lowpointtarget4.x-=.1;
6723                                                                                                                                 lowpoint5.z-=.1;
6724                                                                                                                                 lowpointtarget5.z-=.1;
6725                                                                                                                                 lowpoint6.y+=45/13;
6726                                                                                                                                 lowpointtarget6.y+=45/13;
6727                                                                                                                                 lowpointtarget6+=facing*.6;
6728                                                                                                                                 lowpointtarget7.y+=90/13;
6729                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6730                                                                                                                                 if(objects.friction[i]>.5)
6731                                                                                                                                         if(whichhit!=-1){
6732                                                                                                                                                 //if(k==0){
6733                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6734                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6735                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6736                                                                                                                                                                 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)
6737                                                                                                                                                                         for(j=0;j<45;j++){
6738                                                                                                                                                                                 lowpoint=player[k].coords;
6739                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6740                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6741                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6742                                                                                                                                                                                         if(j<=6){
6743                                                                                                                                                                                                 j=100;
6744                                                                                                                                                                                         }
6745                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6746                                                                                                                                                                                         j=100;
6747                                                                                                                                                                                         }*/
6748                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6749                                                                                                                                                                                                 j=100;
6750                                                                                                                                                                                         }
6751                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6752                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6753                                                                                                                                                                                                 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)*/){
6754                                                                                                                                                                                                         lowpoint=player[k].coords;
6755                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6756                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6757                                                                                                                                                                                                         flatfacing=player[k].coords;
6758                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6759                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6760                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6761
6762                                                                                                                                                                                                         if(j>10||!player[k].isRun()){                                                                                                   
6763                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6764                                                                                                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6765                                                                                                                                                                                                                 }
6766                                                                                                                                                                                                                 float gLoc[3];
6767                                                                                                                                                                                                                 float vel[3];
6768                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6769                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6770                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6771                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6772                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6773                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6774                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
6775                                                                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6776                                                                                                                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
6777                                                                                                                                                                                                                 FSOUND_SetPaused(channels[jumpsound], FALSE);
6778
6779                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6780                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6781                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6782                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6783                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6784                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6785
6786                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6787                                                                                                                                                                                                                 player[k].velocity=0;
6788
6789                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6790                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6791                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6792                                                                                                                                                                                                                         player[k].jumppower=0;
6793                                                                                                                                                                                                                         player[k].jumpclimb=1;
6794                                                                                                                                                                                                                 }
6795                                                                                                                                                                                                                 player[k].transspeed=6;
6796                                                                                                                                                                                                                 player[k].target=0;
6797
6798                                                                                                                                                                                                                 //player[k].currentframe=1;
6799                                                                                                                                                                                                                 player[k].targetframe=1;
6800                                                                                                                                                                                                                 if(j>25){
6801                                                                                                                                                                                                                         //player[k].currentframe=0;
6802                                                                                                                                                                                                                         player[k].targetframe=0;
6803                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6804                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6805                                                                                                                                                                                                                         player[k].jumppower=0;
6806                                                                                                                                                                                                                 }       
6807                                                                                                                                                                                                         }
6808                                                                                                                                                                                                         j=100;
6809                                                                                                                                                                                                 }
6810                                                                                                                                                                                         }
6811                                                                                                                                                                                 }
6812                                                                                                                                                                         }
6813                                                                                                                                                                         //}
6814                                                                                                                                         }
6815                                                                                                                         }
6816                                                                                                                 }
6817                                                                                                         }
6818                                                                                         }
6819                                                                                         if(player[k].collide<=0){
6820                                                                                                 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()){
6821                                                                                                         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)){
6822                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6823                                                                                                                 player[k].targetanimation=jumpdownanim;
6824                                                                                                                 player[k].targetframe=0;
6825                                                                                                                 player[k].target=0;
6826
6827                                                                                                                 float gLoc[3];
6828                                                                                                                 float vel[3];
6829                                                                                                                 gLoc[0]=player[k].coords.x;
6830                                                                                                                 gLoc[1]=player[k].coords.y;
6831                                                                                                                 gLoc[2]=player[k].coords.z;
6832                                                                                                                 vel[0]=player[k].velocity.x;
6833                                                                                                                 vel[1]=player[k].velocity.y;
6834                                                                                                                 vel[2]=player[k].velocity.z;
6835                                                                                                                 if(k==0){
6836                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
6837                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6838                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
6839                                                                                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
6840                                                                                                                 }
6841                                                                                                         }
6842                                                                                                         player[k].velocity.y+=gravity;
6843                                                                                                 }
6844                                                                                         }
6845                                                                 }
6846                                                         }
6847                                                         player[k].realoldcoords=player[k].coords;
6848                                                 }
6849
6850                                                 static XYZ oldviewer;
6851
6852                                                 if(indialogue==-1){
6853                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6854                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6855                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6856                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6857                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6858                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6859                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6860                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6861                                                 }
6862                                                 else
6863                                                 {
6864                                                         player[0].forwardkeydown=0;
6865                                                         player[0].leftkeydown=0;
6866                                                         player[0].backkeydown=0;
6867                                                         player[0].rightkeydown=0;
6868                                                         player[0].jumpkeydown=0;
6869                                                         player[0].crouchkeydown=0;
6870                                                         player[0].drawkeydown=0;
6871                                                         player[0].throwkeydown=0;
6872                                                 }
6873
6874                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6875
6876
6877                                                 static bool endkeydown;
6878                                                 if(indialogue!=-1){
6879                                                         cameramode=1;
6880                                                         if(directing){  
6881                                                                 facing=0;
6882                                                                 facing.z=-1;
6883
6884                                                                 facing=DoRotation(facing,-rotation2,0,0);
6885                                                                 facing=DoRotation(facing,0,0-rotation,0);
6886
6887                                                                 flatfacing=0;
6888                                                                 flatfacing.z=-1;
6889
6890                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6891
6892                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6893                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6894                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6895                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6896                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6897                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6898                                                                 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)
6899                                                                         ||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)
6900                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6901                                                                                 int whichend;
6902                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6903                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6904                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6905                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6906                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6907                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6908                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6909                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6910                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6911                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6912                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6913                                                                                 if(whichend!=-1){
6914                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6915                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6916                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6917                                                                                 }
6918                                                                                 if(whichend==-1){
6919                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6920                                                                                 }
6921                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6922                                                                                         indialogue=-1;
6923                                                                                         directing=0;
6924                                                                                         cameramode=0;
6925                                                                                 }
6926                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6927                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6928                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6929                                                                                 indialogue++;
6930                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6931                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6932                                                                                                 static float gLoc[3];
6933                                                                                                 static float vel[3];
6934                                                                                                 XYZ temppos;
6935                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6936                                                                                                 temppos=temppos-viewer;
6937                                                                                                 Normalise(&temppos);
6938                                                                                                 temppos+=viewer;
6939
6940                                                                                                 gLoc[0]=temppos.x;
6941                                                                                                 gLoc[1]=temppos.y;
6942                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
6943                                                                                                 vel[1]=0;
6944                                                                                                 vel[2]=0;
6945                                                                                                 int whichsoundplay;
6946                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6947                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6948                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6949                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6950                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6951                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6952                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6953                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6954                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6955                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6956                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6957                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6958                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6959                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6960                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6961                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6962                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6963                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6964                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6965                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6966                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
6967                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6968                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
6969                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
6970                                                                                         }
6971                                                                                 }
6972
6973                                                                                 for(j=0;j<numplayers;j++){
6974                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6975                                                                                 }
6976
6977                                                                                 endkeydown=1;
6978                                                                         }
6979                                                                         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)
6980                                                                                 ||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)
6981                                                                                 )){
6982                                                                                         int whichend;
6983                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
6984                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
6985                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
6986                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
6987                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
6988                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
6989                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
6990                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
6991                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
6992                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
6993                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
6994                                                                                 }
6995                                                                                 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)
6996                                                                                         &&!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)
6997                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6998                                                                                                 endkeydown=0;
6999                                                                                         }
7000                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7001                                                                                                 indialogue=-1;
7002                                                                                                 directing=0;
7003                                                                                                 cameramode=0;
7004                                                                                         }
7005                                                         }
7006                                                         if(!directing){ 
7007                                                                 FSOUND_SetPaused(channels[whooshsound], TRUE);
7008                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
7009                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
7010                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
7011                                                                 }                               
7012                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
7013                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
7014                                                                 if(dialoguetime>0.5)
7015                                                                         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)
7016                                                                                 ||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)
7017                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
7018                                                                                         indialogue++;
7019                                                                                         endkeydown=1;
7020                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
7021                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
7022                                                                                                         static float gLoc[3];
7023                                                                                                         static float vel[3];
7024                                                                                                         XYZ temppos;
7025                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7026                                                                                                         temppos=temppos-viewer;
7027                                                                                                         Normalise(&temppos);
7028                                                                                                         temppos+=viewer;
7029
7030                                                                                                         gLoc[0]=temppos.x;
7031                                                                                                         gLoc[1]=temppos.y;
7032                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
7033                                                                                                         vel[1]=0;
7034                                                                                                         vel[2]=0;
7035                                                                                                         int whichsoundplay;
7036                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7037                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7038                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7039                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7040                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7041                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7042                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7043                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7044                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7045                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7046                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7047                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7048                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7049                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7050                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7051                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7052                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7053                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7054                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7055                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7056                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
7057                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
7058                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
7059                                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7060                                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
7061                                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
7062                                                                                                         }
7063                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
7064                                                                                                                 hotspot[numhotspots]=player[0].coords;
7065                                                                                                                 hotspotsize[numhotspots]=10;
7066                                                                                                                 hotspottype[numhotspots]=-1;
7067
7068                                                                                                                 numhotspots++;
7069                                                                                                         }
7070                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
7071                                                                                                                 hostile=1;
7072                                                                                                         }
7073
7074                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
7075                                                                                                                 indialogue=-1;
7076                                                                                                                 directing=0;
7077                                                                                                                 cameramode=0;
7078                                                                                                         }
7079                                                                                                 }
7080                                                                                         }
7081                                                                                 }
7082                                                                                 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)
7083                                                                                         &&!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)
7084                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7085                                                                                                 endkeydown=0;
7086                                                                                         }
7087                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7088                                                                                                 indialogue=-1;
7089                                                                                                 directing=0;
7090                                                                                                 cameramode=0;
7091                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
7092                                                                                                         hostile=1;
7093                                                                                                 }
7094                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
7095                                                                                                         windialogue=1;
7096                                                                                                 }
7097                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
7098                                                                                                         hostile=1;
7099                                                                                                         for(i=1;i<numplayers;i++){
7100                                                                                                                 player[i].aitype = attacktypecutoff;
7101                                                                                                         }
7102                                                                                                 }
7103                                                                                         }
7104                                                         }
7105                                                 }
7106
7107                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
7108                                                 else oldbuttondialogue=1;
7109
7110                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
7111
7112                                                 //Net updates
7113
7114                                                 /*keyrefreshdelay-=multiplier;
7115                                                 bigrefreshdelay-=multiplier;
7116
7117                                                 if(keyrefreshdelay<=0){
7118                                                 static int concat[4];
7119
7120                                                 concat[0]=player[0].forwardkeydown;
7121                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
7122                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
7123                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
7124                                                 concat[0]=concat[0]*2+player[0].backkeydown;
7125                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
7126                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
7127                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
7128
7129                                                 concat[1]=player[0].crouchtogglekeydown;
7130                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
7131                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
7132                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
7133                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
7134                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
7135
7136                                                 //concat[2]=(char)((int)(rotation/2)%180);
7137
7138                                                 //concat[3]=(char)((int)(rotation2/2)%180);
7139
7140                                                 chatname[0]=concat[0]-128;
7141                                                 chatname[1]=concat[1]-128;
7142                                                 //chatname[2]=concat[2]-128;
7143                                                 //chatname[3]=concat[3]-128;
7144                                                 int temppoint=2;
7145                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
7146                                                 temppoint+=sizeof(float);
7147                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
7148                                                 temppoint+=sizeof(float);
7149
7150                                                 chatname[temppoint]='\0';
7151
7152                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
7153                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
7154                                                 //keyrefreshdelay=.01;
7155                                                 keyrefreshdelay=.03;
7156                                                 }
7157
7158                                                 if(bigrefreshdelay<=0){
7159                                                 for(i=0;i<1;i++){
7160                                                 /*int temppoint=0;
7161                                                 memcpy(chatname+temppoint,&i,sizeof(int));
7162                                                 temppoint+=sizeof(int);
7163                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
7164                                                 temppoint+=sizeof(float);
7165                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
7166                                                 temppoint+=sizeof(float);
7167                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
7168                                                 temppoint+=sizeof(float);
7169                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
7170                                                 temppoint+=sizeof(float);
7171                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
7172                                                 temppoint+=sizeof(float);
7173                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
7174                                                 temppoint+=sizeof(int);
7175                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
7176                                                 temppoint+=sizeof(int);
7177                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
7178                                                 temppoint+=sizeof(float);
7179                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
7180                                                 temppoint+=sizeof(float);
7181                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
7182                                                 temppoint+=sizeof(float);
7183                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
7184                                                 temppoint+=sizeof(int);
7185                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
7186                                                 temppoint+=sizeof(int);
7187                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
7188                                                 temppoint+=sizeof(float);
7189                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
7190                                                 temppoint+=sizeof(float);
7191                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
7192                                                 temppoint+=sizeof(float);
7193                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
7194                                                 temppoint+=sizeof(int);
7195                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
7196                                                 temppoint+=sizeof(int);
7197                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
7198                                                 temppoint+=sizeof(int);
7199                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
7200                                                 temppoint+=sizeof(int);
7201                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
7202                                                 temppoint+=sizeof(int);
7203                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
7204                                                 temppoint+=sizeof(int);
7205                                                 chatname[temppoint]='\0';
7206
7207                                                 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);
7208                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
7209                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
7210
7211                                                 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);
7212
7213                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
7214                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
7215                                                 }
7216                                                 //bigrefreshdelay=.02;
7217                                                 bigrefreshdelay=.1;
7218                                                 }
7219                                                 }*/
7220
7221                                                 if(!player[0].jumpkeydown){
7222                                                         player[0].jumptogglekeydown=0;
7223                                                 }
7224                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
7225
7226
7227                                                 dialoguetime+=multiplier;
7228                                                 skybox.cloudmove+=multiplier;
7229                                                 hawkrotation+=multiplier*25;
7230                                                 realhawkcoords=0;
7231                                                 realhawkcoords.x=25;
7232                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
7233                                                 hawkcalldelay-=multiplier/2;
7234
7235                                                 if(hawkcalldelay<=0)
7236                                                 {
7237                                                         static float gLoc[3];
7238                                                         static float vel[3];
7239                                                         gLoc[0]=realhawkcoords.x;
7240                                                         gLoc[1]=realhawkcoords.y;
7241                                                         gLoc[2]=realhawkcoords.z;
7242                                                         vel[0]=0;
7243                                                         vel[1]=0;
7244                                                         vel[2]=0;
7245                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, TRUE);
7246                                                         FSOUND_3D_SetAttributes(channels[hawksound], gLoc, vel);
7247                                                         FSOUND_SetVolume(channels[hawksound], 128);
7248                                                         FSOUND_SetPaused(channels[hawksound], FALSE);
7249
7250                                                         hawkcalldelay=16+abs(Random()%8);
7251                                                 }
7252                                                 static float temptexdetail;
7253
7254
7255                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7256                                                         player[0].damagetolerance=200000;
7257                                                         player[0].damage=0;
7258                                                         player[0].burnt=0;
7259                                                         player[0].permanentdamage=0;
7260                                                         player[0].superpermanentdamage=0;
7261                                                         /*
7262                                                         int whichchar;
7263                                                         whichchar = abs(Random()%7);
7264                                                         registrationname[whichchar]+=1;
7265                                                         */
7266                                                 }
7267
7268                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7269                                                         environment++;
7270                                                         if(environment>2)environment=0;
7271                                                         Setenvironment(environment);
7272
7273                                                         envtogglekeydown=1;
7274                                                 }
7275
7276
7277                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7278                                                         envtogglekeydown=0;
7279                                                 }
7280
7281                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7282                                                         cameramode=1-cameramode;
7283                                                         cameratogglekeydown=1;
7284                                                 }
7285
7286                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7287                                                         cameratogglekeydown=0;
7288                                                 }
7289
7290                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7291                                                         if(player[0].num_weapons>0){
7292                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7293                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7294                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7295                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7296                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7297                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7298                                                                         weapons.length[player[0].weaponids[0]]=.8;
7299                                                                 }
7300                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7301                                                                         weapons.mass[player[0].weaponids[0]]=2;
7302                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7303                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7304                                                                 }
7305
7306                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7307                                                                         weapons.mass[player[0].weaponids[0]]=1;
7308                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7309                                                                         weapons.length[player[0].weaponids[0]]=.25;
7310                                                                 }
7311                                                         }
7312
7313                                                         /*for(i=0;i<objects.numobjects;i++){
7314                                                         if(objects.type[i]==treeleavestype){
7315                                                         for(j=0;j<objects.numobjects;j++){
7316                                                         if(objects.type[j]==treetrunktype)
7317                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7318                                                         objects.scale[i]=objects.scale[j];      
7319                                                         }
7320                                                         }
7321                                                         }*/
7322                                                         detailtogglekeydown=1;
7323                                                 }
7324
7325                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7326                                                         int closest=-1;
7327                                                         float closestdist=-1;
7328                                                         float distance;
7329                                                         if(numplayers>1)
7330                                                                 for(i=1;i<numplayers;i++){
7331                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7332                                                                         if(closestdist==-1||distance<closestdist){
7333                                                                                 closestdist=distance;
7334                                                                                 closest=i;
7335                                                                         }
7336                                                                 }
7337                                                                 if(closest!=-1){
7338                                                                         if(player[closest].num_weapons)
7339                                                                         {
7340                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7341                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7342                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7343                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7344                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7345                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7346                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7347                                                                                 }
7348                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7349                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7350                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7351                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7352                                                                                 }
7353                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7354                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7355                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7356                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7357                                                                                 }
7358                                                                         }
7359                                                                         if(!player[closest].num_weapons)
7360                                                                         {
7361                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7362                                                                                 weapons.owner[weapons.numweapons]=closest;
7363                                                                                 weapons.type[weapons.numweapons]=knife;
7364                                                                                 weapons.damage[weapons.numweapons]=0;
7365                                                                                 weapons.numweapons++;
7366                                                                                 player[closest].num_weapons=1;
7367                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7368                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7369                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7370                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7371                                                                                 }
7372                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7373                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7374                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7375                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7376                                                                                 }
7377                                                                         }
7378                                                                 }
7379                                                                 detailtogglekeydown=1;
7380                                                 }
7381
7382                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7383                                                         int closest=-1;
7384                                                         float closestdist=-1;
7385                                                         float distance;
7386                                                         if(numplayers>1)
7387                                                                 for(i=1;i<numplayers;i++){
7388                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7389                                                                         if(closestdist==-1||distance<closestdist){
7390                                                                                 closestdist=distance;
7391                                                                                 closest=i;
7392                                                                         }
7393                                                                 }
7394
7395                                                                 player[closest].rotation+=multiplier*50;
7396                                                                 player[closest].targetrotation=player[closest].rotation;
7397                                                 }
7398
7399
7400                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7401                                                         int closest=-1;
7402                                                         float closestdist=-1;
7403                                                         float distance;
7404                                                         if(numplayers>1)
7405                                                                 for(i=1;i<numplayers;i++){
7406                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7407                                                                         if(closestdist==-1||distance<closestdist){
7408                                                                                 closestdist=distance;
7409                                                                                 closest=i;
7410                                                                         }
7411                                                                 }
7412                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7413
7414                                                                 if(closest!=-1){
7415                                                                         player[closest].whichskin++;
7416                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7417                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7418
7419                                                                         if(player[closest].creature==rabbittype){
7420                                                                                 if(player[closest].whichskin==0){
7421                                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7422                                                                                 }
7423                                                                                 else if(player[closest].whichskin==1){
7424                                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7425                                                                                 }
7426                                                                                 else if(player[closest].whichskin==2){
7427                                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7428                                                                                 }
7429                                                                                 else if(player[closest].whichskin==3){
7430                                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7431                                                                                 }
7432                                                                                 else if(player[closest].whichskin==4){
7433                                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7434                                                                                 }
7435                                                                                 else if(player[closest].whichskin==5){
7436                                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7437                                                                                 }
7438                                                                                 else if(player[closest].whichskin==6){
7439                                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7440                                                                                 }
7441                                                                                 else if(player[closest].whichskin==7){
7442                                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7443                                                                                 }
7444                                                                                 else if(player[closest].whichskin==8){
7445                                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7446                                                                                 }
7447                                                                                 else if(player[closest].whichskin==9){
7448                                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7449                                                                                 }
7450                                                                         }
7451                                                                         if(player[closest].creature==wolftype){
7452                                                                                 k=abs(Random()%3);
7453                                                                                 if(player[closest].whichskin==0){
7454                                                                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7455                                                                                 }
7456                                                                                 else if(player[closest].whichskin==1){
7457                                                                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7458                                                                                 }
7459                                                                                 else if(player[closest].whichskin==2){
7460                                                                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7461                                                                                 }
7462                                                                         }
7463                                                                 }
7464
7465                                                                 if(player[closest].numclothes){
7466                                                                         for(i=0;i<player[closest].numclothes;i++){
7467                                                                                 tintr=player[closest].clothestintr[i];
7468                                                                                 tintg=player[closest].clothestintg[i];
7469                                                                                 tintb=player[closest].clothestintb[i];
7470                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7471                                                                         }
7472                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7473                                                                 }
7474
7475                                                                 detailtogglekeydown=1;
7476                                                 }
7477
7478                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7479                                                         int closest=-1;
7480                                                         float closestdist=-1;
7481                                                         float distance;
7482                                                         if(numplayers>1)
7483                                                                 for(i=1;i<numplayers;i++){
7484                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7485                                                                         if(closestdist==-1||distance<closestdist){
7486                                                                                 closestdist=distance;
7487                                                                                 closest=i;
7488                                                                         }
7489                                                                 }
7490                                                                 if(closest!=-1){
7491                                                                         if(player[closest].creature==wolftype){
7492                                                                                 headprop=player[closest].proportionhead.x/1.1;
7493                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7494                                                                                 armprop=player[closest].proportionarms.x/1.1;
7495                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7496                                                                         }
7497
7498                                                                         if(player[closest].creature==rabbittype){
7499                                                                                 headprop=player[closest].proportionhead.x/1.2;
7500                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7501                                                                                 armprop=player[closest].proportionarms.x/1.00;
7502                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7503                                                                         }
7504
7505
7506                                                                         if(player[closest].creature==rabbittype){
7507                                                                                 player[closest].skeleton.id=closest;
7508                                                                                 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);
7509                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7510                                                                                 player[closest].whichskin=0;
7511                                                                                 player[closest].creature=wolftype;
7512
7513                                                                                 player[closest].proportionhead=1.1;
7514                                                                                 player[closest].proportionbody=1.1;
7515                                                                                 player[closest].proportionarms=1.1;
7516                                                                                 player[closest].proportionlegs=1.1;
7517                                                                                 player[closest].proportionlegs.y=1.1;
7518                                                                                 player[closest].scale=.23*5*player[0].scale;
7519
7520                                                                                 player[closest].damagetolerance=300;
7521                                                                         }
7522                                                                         else
7523                                                                         {
7524                                                                                 player[closest].skeleton.id=closest;
7525                                                                                 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);
7526                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7527                                                                                 player[closest].whichskin=0;
7528                                                                                 player[closest].creature=rabbittype;
7529
7530                                                                                 player[closest].proportionhead=1.2;
7531                                                                                 player[closest].proportionbody=1.05;
7532                                                                                 player[closest].proportionarms=1.00;
7533                                                                                 player[closest].proportionlegs=1.1;
7534                                                                                 player[closest].proportionlegs.y=1.05;
7535                                                                                 player[closest].scale=.2*5*player[0].scale;
7536
7537                                                                                 player[closest].damagetolerance=200;
7538                                                                         }
7539
7540                                                                         if(player[closest].creature==wolftype){
7541                                                                                 player[closest].proportionhead=1.1*headprop;
7542                                                                                 player[closest].proportionbody=1.1*bodyprop;
7543                                                                                 player[closest].proportionarms=1.1*armprop;
7544                                                                                 player[closest].proportionlegs=1.1*legprop;
7545                                                                         }
7546
7547                                                                         if(player[closest].creature==rabbittype){
7548                                                                                 player[closest].proportionhead=1.2*headprop;
7549                                                                                 player[closest].proportionbody=1.05*bodyprop;
7550                                                                                 player[closest].proportionarms=1.00*armprop;
7551                                                                                 player[closest].proportionlegs=1.1*legprop;
7552                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7553                                                                         }
7554
7555                                                                 }
7556                                                                 detailtogglekeydown=1;
7557                                                 }
7558
7559                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7560                                                         detailtogglekeydown=0;
7561                                                 }
7562
7563                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7564                                                         slomo=1-slomo;
7565                                                         slomodelay=1000;
7566                                                         slomotogglekeydown=1;
7567                                                 }
7568
7569
7570                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7571                                                         int closest=-1;
7572                                                         float closestdist=-1;
7573                                                         float distance;
7574                                                         XYZ flatfacing2,flatvelocity2;
7575                                                         XYZ blah;
7576                                                         if(numplayers>1)
7577                                                                 for(i=1;i<numplayers;i++){
7578                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7579                                                                         if(distance<144&&!player[i].headless)
7580                                                                                 if(closestdist==-1||distance<closestdist){
7581                                                                                         closestdist=distance;
7582                                                                                         closest=i;
7583                                                                                         blah = player[i].coords;
7584                                                                                 }
7585                                                                 }
7586
7587                                                                 if(closest!=-1){                
7588                                                                         XYZ headspurtdirection;
7589                                                                         int i = player[closest].skeleton.jointlabels[head];
7590                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7591                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7592                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7593                                                                                 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;
7594                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7595                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7596                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7597                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7598                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7599                                                                                 Normalise(&headspurtdirection);
7600                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7601                                                                                 flatvelocity2+=headspurtdirection*8;
7602                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7603                                                                         }
7604                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7605
7606                                                                         float gLoc[3];
7607                                                                         float vel[3];
7608                                                                         gLoc[0]=blah.x;
7609                                                                         gLoc[1]=blah.y;
7610                                                                         gLoc[2]=blah.z;
7611                                                                         vel[0]=0;
7612                                                                         vel[1]=0;
7613                                                                         vel[2]=0;
7614                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
7615                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7616                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7617                                                                         FSOUND_SetPaused(channels[splattersound], FALSE);
7618
7619                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
7620                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7621                                                                         FSOUND_SetVolume(channels[breaksound2], 100);
7622                                                                         FSOUND_SetPaused(channels[breaksound2], FALSE);
7623
7624                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7625                                                                         player[closest].RagDoll(0);
7626                                                                         player[closest].dead=2;
7627                                                                         player[closest].headless=1;
7628                                                                         player[closest].DoBloodBig(3,165);
7629
7630                                                                         camerashake+=.3;
7631                                                                 }
7632
7633                                                                 explodetogglekeydown=1;
7634                                                 }
7635
7636                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7637                                                         int closest=-1;
7638                                                         float closestdist=-1;
7639                                                         float distance;
7640                                                         XYZ flatfacing2,flatvelocity2;
7641                                                         XYZ blah;
7642                                                         if(numplayers>1)
7643                                                                 for(i=1;i<numplayers;i++){
7644                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7645                                                                         if(distance<144)
7646                                                                                 if(closestdist==-1||distance<closestdist){
7647                                                                                         closestdist=distance;
7648                                                                                         closest=i;
7649                                                                                         blah=player[i].coords;
7650                                                                                 }
7651                                                                 }
7652
7653                                                                 if(closest!=-1){                
7654                                                                         float gLoc[3];
7655                                                                         float vel[3];
7656                                                                         gLoc[0]=blah.x;
7657                                                                         gLoc[1]=blah.y;
7658                                                                         gLoc[2]=blah.z;
7659                                                                         vel[0]=0;
7660                                                                         vel[1]=0;
7661                                                                         vel[2]=0;
7662
7663                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
7664                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7665                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7666                                                                         FSOUND_SetPaused(channels[splattersound], FALSE);
7667
7668                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
7669                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7670                                                                         FSOUND_SetVolume(channels[breaksound2], 600);
7671                                                                         FSOUND_SetPaused(channels[breaksound2], FALSE);
7672
7673                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7674                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7675                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7676                                                                                 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;
7677                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7678                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7679                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7680                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7681                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7682                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7683                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7684                                                                         }
7685
7686                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7687                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7688                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7689                                                                                 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;
7690                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7691                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7692                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7693                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7694                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7695                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7696                                                                         }
7697
7698                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7699                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7700                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7701                                                                                 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;
7702                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7703                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7704                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7705                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7706                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7707                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7708                                                                         }
7709
7710                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7711                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7712                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7713                                                                                 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;
7714                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7715                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7716                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7717                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7718                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7719                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7720                                                                         }
7721
7722                                                                         XYZ temppos;
7723                                                                         for(j=0;j<numplayers; j++){
7724                                                                                 if(j!=closest){
7725                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7726                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7727                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7728                                                                                                 player[j].skeleton.longdead=0;
7729                                                                                                 player[j].RagDoll(0);
7730                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7731                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7732                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7733                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7734                                                                                                                 Normalise(&flatvelocity2);
7735                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7736                                                                                                         }
7737                                                                                                 }
7738                                                                                         }
7739                                                                                 }
7740                                                                         }
7741
7742                                                                         player[closest].DoDamage(10000);
7743                                                                         player[closest].RagDoll(0);
7744                                                                         player[closest].dead=2;
7745                                                                         player[closest].coords=20;
7746                                                                         player[closest].skeleton.free=2;
7747
7748                                                                         camerashake+=.6;
7749
7750                                                                 }
7751
7752                                                                 explodetogglekeydown=1;
7753                                                 }
7754
7755                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7756                                                         explodetogglekeydown=0;
7757                                                 }
7758
7759                                                 /*
7760                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7761                                                 FILE                    *tfile;
7762                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7763                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7764                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7765                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7766                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7767                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7768                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7769
7770                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7771                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7772                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7773                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7774                                                 for(j=0;j<player[0].num_weapons;j++){
7775                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7776                                                 }
7777                                                 fwrite( &environment, 1, sizeof(int), tfile );
7778
7779                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7780                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7781                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7782                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7783                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7784
7785                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7786                                                 if(numplayers>1&&numplayers<maxplayers)
7787                                                 for(i=1;i<numplayers;i++){
7788                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7789                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7790                                                 for(j=0;j<player[i].num_weapons;j++){
7791                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7792                                                 }
7793                                                 if(player[i].numwaypoints<30){
7794                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7795                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7796                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7797                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7798                                                 }
7799                                                 else{
7800                                                 player[i].numwaypoints=0;
7801                                                 player[i].waypoint=0;
7802                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7803                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7804                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7805                                                 }
7806                                                 }
7807
7808                                                 fclose(tfile);
7809
7810                                                 slomotogglekeydown=1;
7811                                                 }*/
7812
7813                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7814                                                         slomotogglekeydown=0;
7815                                                 }
7816
7817
7818                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7819                                                         player[0].onfire=1-player[0].onfire;
7820                                                         if(player[0].onfire){
7821                                                                 player[0].CatchFire();
7822                                                         }
7823                                                         if(!player[0].onfire){
7824                                                                 float gLoc[3];
7825                                                                 float vel[3];
7826                                                                 gLoc[0]=player[0].coords.x;
7827                                                                 gLoc[1]=player[0].coords.y;
7828                                                                 gLoc[2]=player[0].coords.z;
7829                                                                 vel[0]=0;
7830                                                                 vel[1]=0;
7831                                                                 vel[2]=0;
7832                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
7833                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7834                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
7835                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
7836                                                                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
7837                                                         }
7838                                                         slomotogglekeydown=1;
7839                                                 }
7840                                                 /*
7841                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7842                                                 if(player[0].bleeding<=0)
7843                                                 player[0].DoBlood(1,255);
7844                                                 }*/
7845
7846
7847                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7848                                                         int closest=-1;
7849                                                         float closestdist=-1;
7850                                                         float distance;
7851                                                         if(numplayers>1)
7852                                                                 for(i=1;i<numplayers;i++){
7853                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7854                                                                         if(closestdist==-1||distance<closestdist){
7855                                                                                 closestdist=distance;
7856                                                                                 closest=i;
7857                                                                         }
7858                                                                 }
7859                                                                 if(closestdist>0&&closest>=0){
7860                                                                         //player[closest]=player[numplayers-1];
7861                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7862                                                                         numplayers--;
7863                                                                 }
7864                                                                 drawmodetogglekeydown=1;
7865                                                 }
7866
7867                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7868                                                         int closest=-1;
7869                                                         float closestdist=-1;
7870                                                         float distance;
7871                                                         if(max_objects>1)
7872                                                                 for(i=1;i<max_objects;i++){
7873                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7874                                                                         if(closestdist==-1||distance<closestdist){
7875                                                                                 closestdist=distance;
7876                                                                                 closest=i;
7877                                                                         }
7878                                                                 }
7879                                                                 if(closestdist>0&&closest>=0){
7880                                                                         objects.position[closest].y-=500;
7881                                                                 }
7882                                                                 drawmodetogglekeydown=1;
7883                                                 }
7884
7885                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7886                                                         //drawmode++;
7887                                                         //if(drawmode>2)drawmode=0;
7888                                                         if(objects.numobjects<max_objects-1){                   
7889                                                                 XYZ boxcoords;
7890                                                                 boxcoords.x=player[0].coords.x;
7891                                                                 boxcoords.z=player[0].coords.z;
7892                                                                 boxcoords.y=player[0].coords.y-3;
7893                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7894                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7895                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7896                                                                 float temprotat,temprotat2;
7897                                                                 temprotat=editorrotation;
7898                                                                 temprotat2=editorrotation2;
7899                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7900                                                                 if(temprotat2<0)temprotat2=Random()%360;
7901
7902                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7903                                                                 if(editortype==treetrunktype)
7904                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7905                                                         }
7906
7907                                                         drawmodetogglekeydown=1;
7908                                                 }
7909
7910                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7911                                                         if(numplayers<maxplayers-1){
7912                                                                 player[numplayers].scale=.2*5*player[0].scale;
7913                                                                 player[numplayers].creature=rabbittype;
7914                                                                 player[numplayers].howactive=editoractive;
7915                                                                 player[numplayers].skeleton.id=numplayers;
7916                                                                 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);
7917
7918                                                                 //texsize=512*512*3/texdetail/texdetail;
7919                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7920                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7921
7922                                                                 k=abs(Random()%2)+1;
7923                                                                 if(k==0){
7924                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7925                                                                         player[numplayers].whichskin=0;
7926                                                                 }
7927                                                                 else if(k==1){
7928                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7929                                                                         player[numplayers].whichskin=1;
7930                                                                 }
7931                                                                 else {
7932                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7933                                                                         player[numplayers].whichskin=2;
7934                                                                 }
7935
7936                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7937                                                                 player[numplayers].power=1;
7938                                                                 player[numplayers].speedmult=1;
7939                                                                 player[numplayers].currentanimation=bounceidleanim;
7940                                                                 player[numplayers].targetanimation=bounceidleanim;
7941                                                                 player[numplayers].currentframe=0;
7942                                                                 player[numplayers].targetframe=1;
7943                                                                 player[numplayers].target=0;
7944                                                                 player[numplayers].bled=0;
7945                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
7946
7947                                                                 player[numplayers].targetrotation=player[0].targetrotation;
7948                                                                 player[numplayers].rotation=player[0].rotation;
7949
7950                                                                 player[numplayers].velocity=0;
7951                                                                 player[numplayers].coords=player[0].coords;
7952                                                                 player[numplayers].oldcoords=player[numplayers].coords;
7953                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
7954
7955                                                                 player[numplayers].id=numplayers;
7956                                                                 player[numplayers].skeleton.id=numplayers;
7957                                                                 player[numplayers].updatedelay=0;
7958                                                                 player[numplayers].normalsupdatedelay=0;
7959
7960                                                                 player[numplayers].aitype=passivetype;
7961                                                                 player[numplayers].aitarget=0;
7962
7963                                                                 if(player[0].creature==wolftype){
7964                                                                         headprop=player[0].proportionhead.x/1.1;
7965                                                                         bodyprop=player[0].proportionbody.x/1.1;
7966                                                                         armprop=player[0].proportionarms.x/1.1;
7967                                                                         legprop=player[0].proportionlegs.x/1.1;
7968                                                                 }
7969
7970                                                                 if(player[0].creature==rabbittype){
7971                                                                         headprop=player[0].proportionhead.x/1.2;
7972                                                                         bodyprop=player[0].proportionbody.x/1.05;
7973                                                                         armprop=player[0].proportionarms.x/1.00;
7974                                                                         legprop=player[0].proportionlegs.x/1.1;
7975                                                                 }
7976
7977                                                                 if(player[numplayers].creature==wolftype){
7978                                                                         player[numplayers].proportionhead=1.1*headprop;
7979                                                                         player[numplayers].proportionbody=1.1*bodyprop;
7980                                                                         player[numplayers].proportionarms=1.1*armprop;
7981                                                                         player[numplayers].proportionlegs=1.1*legprop;
7982                                                                 }
7983
7984                                                                 if(player[numplayers].creature==rabbittype){
7985                                                                         player[numplayers].proportionhead=1.2*headprop;
7986                                                                         player[numplayers].proportionbody=1.05*bodyprop;
7987                                                                         player[numplayers].proportionarms=1.00*armprop;
7988                                                                         player[numplayers].proportionlegs=1.1*legprop;
7989                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
7990                                                                 }
7991
7992                                                                 player[numplayers].headless=0;
7993                                                                 player[numplayers].onfire=0;
7994
7995                                                                 if(cellophane){
7996                                                                         player[numplayers].proportionhead.z=0;
7997                                                                         player[numplayers].proportionbody.z=0;
7998                                                                         player[numplayers].proportionarms.z=0;
7999                                                                         player[numplayers].proportionlegs.z=0;
8000                                                                 }
8001
8002                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
8003
8004                                                                 player[numplayers].damagetolerance=200;
8005
8006                                                                 player[numplayers].protectionhead=player[0].protectionhead;
8007                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
8008                                                                 player[numplayers].protectionlow=player[0].protectionlow;
8009                                                                 player[numplayers].armorhead=player[0].armorhead;
8010                                                                 player[numplayers].armorhigh=player[0].armorhigh;
8011                                                                 player[numplayers].armorlow=player[0].armorlow;
8012                                                                 player[numplayers].metalhead=player[0].metalhead;
8013                                                                 player[numplayers].metalhigh=player[0].metalhigh;
8014                                                                 player[numplayers].metallow=player[0].metallow;
8015
8016                                                                 player[numplayers].immobile=player[0].immobile;
8017
8018                                                                 player[numplayers].numclothes=player[0].numclothes;
8019                                                                 if(player[numplayers].numclothes)
8020                                                                         for(i=0;i<player[numplayers].numclothes;i++){
8021                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
8022                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
8023                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
8024                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
8025                                                                                 tintr=player[numplayers].clothestintr[i];
8026                                                                                 tintg=player[numplayers].clothestintg[i];
8027                                                                                 tintb=player[numplayers].clothestintb[i];
8028                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8029                                                                         }
8030                                                                         if(player[numplayers].numclothes){
8031                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
8032                                                                         }
8033
8034                                                                         player[numplayers].power=player[0].power;
8035                                                                         player[numplayers].speedmult=player[0].speedmult;
8036
8037                                                                         player[numplayers].damage=0;
8038                                                                         player[numplayers].permanentdamage=0;
8039                                                                         player[numplayers].superpermanentdamage=0;
8040                                                                         player[numplayers].deathbleeding=0;
8041                                                                         player[numplayers].bleeding=0;
8042                                                                         player[numplayers].numwaypoints=0;
8043                                                                         player[numplayers].waypoint=0;
8044                                                                         player[numplayers].jumppath=0;
8045                                                                         player[numplayers].weaponstuck=-1;
8046                                                                         player[numplayers].weaponactive=-1;
8047                                                                         player[numplayers].num_weapons=0;
8048                                                                         player[numplayers].bloodloss=0;
8049                                                                         player[numplayers].dead=0;
8050
8051                                                                         player[numplayers].loaded=1;
8052
8053                                                                         numplayers++;
8054                                                         }
8055                                                         drawmodetogglekeydown=1;
8056                                                 }
8057
8058                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
8059                                                         if(player[numplayers-1].numwaypoints<90){
8060                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
8061                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
8062                                                                 player[numplayers-1].numwaypoints++;
8063                                                         }
8064                                                         drawmodetogglekeydown=1;
8065                                                 }
8066
8067                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
8068                                                         if(numpathpoints<30){
8069                                                                 bool connected,alreadyconnected;
8070                                                                 connected=0;
8071                                                                 if(numpathpoints>1)
8072                                                                         for(i=0;i<numpathpoints;i++){
8073                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
8074                                                                                         alreadyconnected=0;
8075                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
8076                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
8077                                                                                         }
8078                                                                                         if(!alreadyconnected){
8079                                                                                                 numpathpointconnect[pathpointselected]++;
8080                                                                                                 connected=1;
8081                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
8082                                                                                         }
8083                                                                                 }
8084                                                                         }
8085                                                                         if(!connected){
8086                                                                                 numpathpoints++;
8087                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
8088                                                                                 numpathpointconnect[numpathpoints-1]=0;
8089                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
8090                                                                                         numpathpointconnect[pathpointselected]++;
8091                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
8092                                                                                 }
8093                                                                                 pathpointselected=numpathpoints-1;
8094                                                                         }
8095                                                         }
8096                                                         drawmodetogglekeydown=1;
8097                                                 }
8098
8099                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
8100                                                         pathpointselected++;
8101                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
8102                                                         drawmodetogglekeydown=1;
8103                                                 }
8104                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8105                                                         pathpointselected--;
8106                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
8107                                                         drawmodetogglekeydown=1;
8108                                                 }
8109                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8110                                                         if(pathpointselected!=-1){
8111                                                                 numpathpoints--;
8112                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
8113                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
8114                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
8115                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
8116                                                                 }
8117                                                                 for(i=0;i<numpathpoints;i++){
8118                                                                         for(j=0;j<numpathpointconnect[i];j++){
8119                                                                                 if(pathpointconnect[i][j]==pathpointselected){
8120                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
8121                                                                                         numpathpointconnect[i]--;
8122                                                                                 }
8123                                                                                 if(pathpointconnect[i][j]==numpathpoints){
8124                                                                                         pathpointconnect[i][j]=pathpointselected;
8125                                                                                 }
8126                                                                         }
8127                                                                 }
8128                                                                 pathpointselected=numpathpoints-1;
8129                                                         }
8130                                                         drawmodetogglekeydown=1;
8131                                                 }
8132
8133                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
8134                                                         editorenabled=1-editorenabled;
8135                                                         if(editorenabled){
8136                                                                 player[0].damagetolerance=100000;
8137                                                                 player[0].damage=0;
8138                                                                 player[0].superpermanentdamage=0;
8139                                                                 player[0].bloodloss=0;
8140                                                                 player[0].deathbleeding=0;
8141                                                         }
8142                                                         if(!editorenabled){
8143                                                                 player[0].damagetolerance=200;
8144                                                                 player[0].damage=0;
8145                                                                 player[0].permanentdamage=0;
8146                                                                 player[0].superpermanentdamage=0;
8147                                                                 player[0].bloodloss=0;
8148                                                                 player[0].deathbleeding=0;
8149                                                         }
8150                                                         drawmodetogglekeydown=1;
8151                                                 }
8152
8153                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8154                                                         editortype--;
8155                                                         if(editortype==treeleavestype||editortype==10)editortype--;
8156                                                         if(editortype<0)editortype=firetype;
8157                                                         drawmodetogglekeydown=1;
8158                                                 }
8159
8160                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8161                                                         editortype++;
8162                                                         if(editortype==treeleavestype||editortype==10)editortype++;
8163                                                         if(editortype>firetype)editortype=0;
8164                                                         drawmodetogglekeydown=1;
8165                                                 }
8166
8167                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8168                                                         editorrotation-=multiplier*100;
8169                                                         if(editorrotation<-.01)editorrotation=-.01;
8170                                                         drawmodetogglekeydown=1;
8171                                                 }
8172
8173                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8174                                                         editorrotation+=multiplier*100;
8175                                                         drawmodetogglekeydown=1;
8176                                                 }
8177
8178                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8179                                                         editorsize+=multiplier;
8180                                                         drawmodetogglekeydown=1;
8181                                                 }
8182
8183                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8184                                                         editorsize-=multiplier;
8185                                                         if(editorsize<.1)editorsize=.1;
8186                                                         drawmodetogglekeydown=1;
8187                                                 }
8188
8189
8190                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8191                                                         mapradius-=multiplier*10;
8192                                                 }
8193
8194                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8195                                                         mapradius+=multiplier*10;
8196                                                 }
8197                                                 /*
8198                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8199                                                 mapcenter.x+=multiplier*20;
8200                                                 }
8201
8202                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8203                                                 mapcenter.x-=multiplier*20;
8204                                                 }
8205
8206                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8207                                                 mapcenter.z+=multiplier*20;
8208                                                 }
8209
8210                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8211                                                 mapcenter.z-=multiplier*20;
8212                                                 }
8213                                                 */
8214                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8215                                                         editorrotation2+=multiplier*100;
8216                                                 }
8217
8218                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8219                                                         editorrotation2-=multiplier*100;
8220                                                         if(editorrotation2<-.01)editorrotation2=-.01;
8221                                                 }
8222                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
8223                                                         int closest=-1;
8224                                                         float closestdist=-1;
8225                                                         float distance;
8226                                                         for(i=0;i<objects.numobjects;i++){
8227                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
8228                                                                 if(closestdist==-1||distance<closestdist){
8229                                                                         closestdist=distance;
8230                                                                         closest=i;
8231                                                                 }
8232                                                         }
8233                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);             
8234                                                         drawmodetogglekeydown=1;
8235                                                 }
8236
8237
8238                                                 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)){
8239                                                         drawmodetogglekeydown=0;
8240                                                 }
8241
8242                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8243                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8244                                                         player[0].RagDoll(0);
8245                                                         //player[0].spurt=1;
8246                                                         //player[0].DoDamage(1000);
8247
8248                                                         float gLoc[3];
8249                                                         float vel[3];
8250                                                         gLoc[0]=player[0].coords.x;
8251                                                         gLoc[1]=player[0].coords.y;
8252                                                         gLoc[2]=player[0].coords.z;
8253                                                         vel[0]=player[0].velocity.x;
8254                                                         vel[1]=player[0].velocity.y;
8255                                                         vel[2]=player[0].velocity.z;
8256                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
8257                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8258                                                         FSOUND_SetVolume(channels[whooshsound], 128);
8259                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
8260                                                         //FSOUND_SetPaused(channels[whooshsound], TRUE);
8261
8262                                                         texturesizetogglekeydown=1;
8263                                                 }
8264
8265                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8266
8267                                                         int closest=-1;
8268                                                         float closestdist=-1;
8269                                                         float distance;
8270                                                         for(i=0;i<objects.numobjects;i++){
8271                                                                 if(objects.type[i]==treeleavestype){
8272                                                                         objects.scale[i]*=.9;
8273                                                                 }
8274                                                         }
8275                                                         texturesizetogglekeydown=1;
8276                                                 }
8277
8278                                                 static XYZ relative;
8279                                                 static int randattack;
8280                                                 //Attack
8281                                                 static bool playerrealattackkeydown=0;
8282
8283                                                 if(!buttons[0])oldbutton=0;
8284                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8285                                                 if(oldattackkey)player[0].attackkeydown=0;
8286                                                 if(oldattackkey)playerrealattackkeydown=0;
8287                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8288                                                 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);
8289                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8290                                                         for(k=0;k<numplayers;k++){
8291                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8292                                                                         player[k].Reverse();
8293                                                         }
8294                                                 }
8295
8296                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8297
8298                                                 for(k=0;k<numplayers;k++){
8299                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8300                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8301                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
8302                                                                 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)){
8303                                                                         player[k].jumppower-=2;
8304                                                                 }
8305                                                                 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)){
8306                                                                         for(i=0;i<numplayers;i++){
8307                                                                                 if(i==k)i++;
8308                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8309                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8310                                                                                                 player[k].targetanimation=dodgebackanim;
8311                                                                                                 player[k].target=0;
8312                                                                                                 player[k].targetframe=0;
8313                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8314                                                                                                 Normalise(&rotatetarget);
8315                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8316                                                                                                 player[k].targetrotation*=360/6.28;
8317                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8318
8319                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8320                                                                                         }
8321                                                                         }
8322                                                                         if(player[k].targetanimation!=dodgebackanim){
8323                                                                                 if(k==0)numflipped++;
8324                                                                                 player[k].targetanimation=backhandspringanim;
8325                                                                                 player[k].target=0;
8326                                                                                 player[k].targetframe=0;
8327                                                                                 player[k].targetrotation=-rotation+180;
8328                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8329                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8330                                                                                 player[k].rotation=player[k].targetrotation;
8331                                                                                 player[k].jumppower-=2;
8332                                                                         }
8333                                                                 }
8334                                                                 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())){
8335                                                                         player[k].hasvictim=0;
8336                                                                         if(numplayers>1)
8337                                                                                 for(i=0;i<numplayers;i++){
8338                                                                                         if(i==k)i++;
8339                                                                                         if(!player[k].hasvictim)
8340                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){      
8341                                                                                                         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){
8342                                                                                                                 player[k].victim=&player[i];
8343                                                                                                                 player[k].hasvictim=1;
8344                                                                                                                 if(player[k].aitype==playercontrolled){
8345                                                                                                                         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;
8346                                                                                                                         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;
8347                                                                                                                         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;
8348                                                                                                                         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;
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&&!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;
8350                                                                                                                         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;
8351                                                                                                                         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;
8352                                                                                                                         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;
8353                                                                                                                         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;
8354                                                                                                                         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;
8355                                                                                                                 }
8356                                                                                                                 else {
8357                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8358                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8359                                                                                                                                 else randattack=abs(Random()%5);
8360                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8361                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8362                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8363                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8364                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8365                                                                                                                                 }
8366                                                                                                                                 if(player[k].weaponactive!=-1){
8367                                                                                                                                         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;
8368                                                                                                                                         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;
8369                                                                                                                                         //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;
8370                                                                                                                                         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;
8371                                                                                                                                         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;
8372                                                                                                                                         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;
8373                                                                                                                                         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;
8374                                                                                                                                         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;
8375                                                                                                                                 }
8376                                                                                                                         }
8377                                                                                                                 }
8378                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8379                                                                                                         }
8380                                                                                                         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)){
8381                                                                                                                 if(player[k].weaponactive==-1){
8382                                                                                                                         player[i].targetanimation=sneakattackedanim;
8383                                                                                                                         player[i].currentanimation=sneakattackedanim;
8384                                                                                                                         player[k].currentanimation=sneakattackanim;
8385                                                                                                                         player[k].targetanimation=sneakattackanim;
8386                                                                                                                         player[k].oldcoords=player[k].coords;
8387                                                                                                                         player[k].coords=player[i].coords;
8388                                                                                                                 }
8389                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8390                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8391                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8392                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8393                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8394                                                                                                                         player[i].oldcoords=player[i].coords;
8395                                                                                                                         player[i].coords=player[k].coords;
8396                                                                                                                 }
8397                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8398                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8399                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8400                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8401                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8402                                                                                                                         player[i].oldcoords=player[i].coords;
8403                                                                                                                         player[i].coords=player[k].coords;
8404                                                                                                                 }
8405                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8406                                                                                                                         player[k].victim=&player[i];
8407                                                                                                                         player[k].hasvictim=1;
8408                                                                                                                         player[i].targettilt2=0;
8409                                                                                                                         player[i].targetframe=1;
8410                                                                                                                         player[i].currentframe=0;
8411                                                                                                                         player[i].target=0;
8412                                                                                                                         player[i].velocity=0;
8413                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8414                                                                                                                         player[k].currentframe=player[i].currentframe;
8415                                                                                                                         player[k].targetframe=player[i].targetframe;
8416                                                                                                                         player[k].target=player[i].target;
8417                                                                                                                         player[k].velocity=0;
8418                                                                                                                         player[k].targetrotation=player[i].rotation;
8419                                                                                                                         player[k].rotation=player[i].rotation;
8420                                                                                                                         player[i].targetrotation=player[i].rotation;
8421                                                                                                                 }
8422                                                                                                         }
8423                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8424                                                                                                                 oldattackkey=1;
8425                                                                                                                 player[k].targetframe=0;
8426                                                                                                                 player[k].target=0;
8427                                                                                                                 //player[k].velocity=0;
8428
8429                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8430                                                                                                                 Normalise(&rotatetarget);
8431                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8432                                                                                                                 player[k].targetrotation*=360/6.28;
8433                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8434
8435                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8436
8437                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8438                                                                                                                 player[k].lastattack2=player[k].lastattack;
8439                                                                                                                 player[k].lastattack=player[k].targetanimation;
8440                                                                                                                 //player[k].targettilt2=0;
8441                                                                                                                 //slomo=1;
8442                                                                                                                 //slomodelay=.2;
8443                                                                                                         }
8444                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8445                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8446                                                                                                                 Normalise(&rotatetarget);
8447                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8448                                                                                                                 player[k].targetrotation*=360/6.28;
8449                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8450                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8451                                                                                                                 oldattackkey=1;
8452                                                                                                                 player[k].victim=&player[i];
8453                                                                                                                 player[k].hasvictim=1;
8454                                                                                                                 player[i].targetanimation=knifefollowedanim;
8455                                                                                                                 player[i].currentanimation=knifefollowedanim;
8456                                                                                                                 player[i].targettilt2=0;
8457                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8458                                                                                                                 player[i].targetframe=1;
8459                                                                                                                 player[i].currentframe=0;
8460                                                                                                                 player[i].target=0;
8461                                                                                                                 player[i].velocity=0;
8462                                                                                                                 player[k].currentanimation=knifefollowanim;
8463                                                                                                                 player[k].targetanimation=knifefollowanim;
8464                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8465                                                                                                                 player[k].currentframe=player[i].currentframe;
8466                                                                                                                 player[k].targetframe=player[i].targetframe;
8467                                                                                                                 player[k].target=player[i].target;
8468                                                                                                                 player[k].velocity=0;
8469                                                                                                                 player[k].oldcoords=player[k].coords;
8470                                                                                                                 player[i].coords=player[k].coords;
8471                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8472                                                                                                                 player[i].rotation=player[k].targetrotation;
8473                                                                                                                 player[k].rotation=player[k].targetrotation;
8474                                                                                                                 player[i].rotation=player[k].targetrotation;
8475                                                                                                         }
8476                                                                                                 }
8477                                                                                 }
8478                                                                                 bool hasstaff=0;
8479                                                                                 if(player[k].weaponactive!=-1){
8480                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8481                                                                                 }
8482                                                                                 if(numplayers>1)
8483                                                                                         for(i=0;i<numplayers;i++){
8484                                                                                                 if(i==k)i++;
8485                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){   
8486                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8487                                                                                                                 if(player[i].skeleton.free)
8488                                                                                                                         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)))){
8489                                                                                                                                 player[k].victim=&player[i];
8490                                                                                                                                 player[k].hasvictim=1;
8491                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8492                                                                                                                                         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;
8493                                                                                                                                         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;
8494                                                                                                                                         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;
8495                                                                                                                                 }
8496                                                                                                                                 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){
8497                                                                                                                                         player[k].targetanimation=killanim;
8498                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8499                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8500                                                                                                                                                         terrain.DeleteDecal(j);
8501                                                                                                                                                 }
8502                                                                                                                                         }
8503                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8504                                                                                                                                                 if(objects.model[l].type==decalstype)
8505                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8506                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8507                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8508                                                                                                                                                                 }
8509                                                                                                                                                         }
8510                                                                                                                                         }
8511                                                                                                                                 }
8512                                                                                                                                 if(!player[i].dead||musictype!=2)
8513                                                                                                                                         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)){
8514                                                                                                                                                 player[k].targetanimation=dropkickanim;
8515                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8516                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8517                                                                                                                                                                 terrain.DeleteDecal(j);
8518                                                                                                                                                         }
8519                                                                                                                                                 }
8520                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8521                                                                                                                                                         if(objects.model[l].type==decalstype)
8522                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8523                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8524                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8525                                                                                                                                                                         }
8526                                                                                                                                                                 }
8527                                                                                                                                                 }
8528                                                                                                                                         }
8529                                                                                                                         }
8530                                                                                                                         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)){
8531                                                                                                                                 oldattackkey=1;
8532                                                                                                                                 player[k].targetframe=0;
8533                                                                                                                                 player[k].target=0;
8534                                                                                                                                 //player[k].velocity=0;
8535
8536                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8537                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8538                                                                                                                                         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;
8539                                                                                                                                 }
8540                                                                                                                                 Normalise(&rotatetarget);
8541                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8542                                                                                                                                 player[k].targetrotation*=360/6.28;
8543                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8544
8545                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8546                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8547                                                                                                                                 }
8548
8549                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8550                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8551
8552                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8553                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8554                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8555
8556                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8557                                                                                                                                         player[k].targetrotation+=30;
8558                                                                                                                                 }
8559                                                                                                                                 //player[k].targettilt2=0;
8560                                                                                                                                 //slomo=1;
8561                                                                                                                                 //slomodelay=.2;
8562                                                                                                                         }
8563                                                                                                 }
8564                                                                                         }
8565                                                                                         if(!player[k].hasvictim){
8566                                                                                                 for(i=0;i<numplayers;i++){
8567                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8568                                                                                                                 player[k].victim=&player[i];
8569                                                                                                                 player[k].hasvictim=1;
8570                                                                                                         }
8571                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8572                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8573                                                                                                                         player[k].victim=&player[i];
8574                                                                                                                 }
8575                                                                                                 }
8576                                                                                         }
8577                                                                                         if(player[k].aitype==playercontrolled)
8578                                                                                                 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)){
8579                                                                                                         oldattackkey=1;
8580                                                                                                         player[k].targetanimation=rabbitkickanim;
8581                                                                                                         player[k].targetframe=0;
8582                                                                                                         player[k].target=0;
8583                                                                                                 }
8584                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8585                                                                                                         numattacks++;
8586                                                                                                         bool armedstaff=0;
8587                                                                                                         if(player[k].weaponactive!=-1){
8588                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8589                                                                                                         }
8590                                                                                                         bool armedsword=0;
8591                                                                                                         if(player[k].weaponactive!=-1){
8592                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8593                                                                                                         }
8594                                                                                                         bool armedknife=0;
8595                                                                                                         if(player[k].weaponactive!=-1){
8596                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8597                                                                                                         }
8598                                                                                                         if(armedstaff)numstaffattack++;
8599                                                                                                         else if(armedsword)numswordattack++;
8600                                                                                                         else if(armedknife)numknifeattack++;
8601                                                                                                         else numunarmedattack++;
8602                                                                                                 }
8603                                                                 }
8604                                                         }
8605                                                 }
8606
8607                                                 //Collisions
8608                                                 static float collisionradius;
8609                                                 if(numplayers>1)
8610                                                         for(k=0;k<numplayers;k++){
8611                                                                 for(i=k;i<numplayers;i++){
8612                                                                         if(i==k)i++;
8613                                                                         if(i<numplayers)
8614                                                                                 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))
8615                                                                                         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))
8616                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8617                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8618                                                                                                                 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)
8619                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8620                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8621                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8622                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8623                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8624                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8625                                                                                                                                                                         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)){
8626                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8627                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8628                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8629                                                                                                                                                                                 }       
8630                                                                                                                                                                         }
8631
8632                                                                                                                                                                         tempcoords1=player[i].coords;
8633                                                                                                                                                                         tempcoords2=player[k].coords;
8634                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8635                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8636                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8637                                                                                                                                                                         if(player[0].hasvictim)
8638                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8639                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){   
8640                                                                                                                                                                                 if(k==0)
8641                                                                                                                                                                                         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)){
8642                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8643                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8644                                                                                                                                                                                                 player[i].skeleton.free=0;
8645                                                                                                                                                                                                 player[i].rotation=0;
8646                                                                                                                                                                                                 player[i].RagDoll(0);
8647                                                                                                                                                                                                 player[i].DoDamage(20);
8648                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8649                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8650                                                                                                                                                                                                 player[k].lastcollide=1;        
8651                                                                                                                                                                                         }
8652                                                                                                                                                                                         if(i==0)
8653                                                                                                                                                                                                 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)){
8654                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8655                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8656                                                                                                                                                                                                         player[k].skeleton.free=0;
8657                                                                                                                                                                                                         player[k].rotation=0;
8658                                                                                                                                                                                                         player[k].RagDoll(0);
8659                                                                                                                                                                                                         player[k].DoDamage(20);
8660                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8661                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8662                                                                                                                                                                                                         player[i].lastcollide=1;        
8663                                                                                                                                                                                                 }
8664
8665                                                                                                                                                                                                 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)){     
8666                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8667                                                                                                                                                                                                         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))
8668                                                                                                                                                                                                                 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))){
8669                                                                                                                                                                                                                         //If hit by body
8670                                                                                                                                                                                                                         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)){
8671                                                                                                                                                                                                                                 static float gLoc[3];
8672                                                                                                                                                                                                                                 static float vel[3];
8673                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8674                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8675                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8676                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8677                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8678                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8679                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8680                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, TRUE);
8681                                                                                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8682                                                                                                                                                                                                                                         FSOUND_SetVolume(channels[heavyimpactsound], 256);
8683                                                                                                                                                                                                                                         FSOUND_SetPaused(channels[heavyimpactsound], FALSE);
8684                                                                                                                                                                                                                                 }
8685                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8686                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8687
8688                                                                                                                                                                                                                                 player[i].RagDoll(0);
8689                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8690                                                                                                                                                                                                                                         bonus=aimbonus;
8691                                                                                                                                                                                                                                         bonustime=0;
8692                                                                                                                                                                                                                                         bonusvalue=150;
8693                                                                                                                                                                                                                                 }
8694                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8695                                                                                                                                                                                                                                 player[k].RagDoll(0);
8696                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8697                                                                                                                                                                                                                                         bonus=aimbonus;
8698                                                                                                                                                                                                                                         bonustime=0;
8699                                                                                                                                                                                                                                         bonusvalue=150;
8700                                                                                                                                                                                                                                 }
8701                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8702
8703                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8704                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8705                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8706                                                                                                                                                                                                                                 }
8707                                                                                                                                                                                                                                 //}
8708                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8709                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8710                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8711                                                                                                                                                                                                                                 }
8712                                                                                                                                                                                                                                 //}
8713
8714                                                                                                                                                                                                                         }
8715                                                                                                                                                                                                                 }
8716                                                                                                                                                                                                                 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)){
8717                                                                                                                                                                                                                         //If bumped
8718                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8719                                                                                                                                                                                                                                 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)){
8720                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8721                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8722                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8723                                                                                                                                                                                                                                         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);
8724                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8725                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8726                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8727                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8728                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8729                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8730                                                                                                                                                                                                                                                                 player[k].target=0;
8731                                                                                                                                                                                                                                                         }
8732                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8733                                                                                                                                                                                                                                                         {
8734                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8735                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8736                                                                                                                                                                                                                                                                 player[k].target=0;
8737                                                                                                                                                                                                                                                         }
8738                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8739                                                                                                                                                                                                                                                 }
8740                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8741                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8742                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8743                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8744                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8745                                                                                                                                                                                                                                                                         player[i].target=0;
8746                                                                                                                                                                                                                                                                 }
8747                                                                                                                                                                                                                                                                 else
8748                                                                                                                                                                                                                                                                 {
8749                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8750                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8751                                                                                                                                                                                                                                                                         player[i].target=0;
8752                                                                                                                                                                                                                                                                 }
8753                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8754                                                                                                                                                                                                                                                         }
8755                                                                                                                                                                                                                                 }
8756                                                                                                                                                                                                                                 if(hostile){
8757                                                                                                                                                                                                                                         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){
8758                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8759                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8760                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8761                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8762                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8763                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8764                                                                                                                                                                                                                                                 player[k].lastcollide=1;        
8765                                                                                                                                                                                                                                                 if(k==0){
8766                                                                                                                                                                                                                                                         bonus=AboveBonus;
8767                                                                                                                                                                                                                                                         bonustime=0;
8768                                                                                                                                                                                                                                                         bonusvalue=50;
8769                                                                                                                                                                                                                                                 }
8770                                                                                                                                                                                                                                         }
8771                                                                                                                                                                                                                                         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){
8772                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8773                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8774                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8775                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8776                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8777                                                                                                                                                                                                                                                 player[k].RagDoll(0);   
8778                                                                                                                                                                                                                                                 player[i].lastcollide=1;        
8779                                                                                                                                                                                                                                                 if(i==0){
8780                                                                                                                                                                                                                                                         bonus=AboveBonus;
8781                                                                                                                                                                                                                                                         bonustime=0;
8782                                                                                                                                                                                                                                                         bonusvalue=50;
8783                                                                                                                                                                                                                                                 }
8784                                                                                                                                                                                                                                         }
8785                                                                                                                                                                                                                                 }
8786                                                                                                                                                                                                                         }
8787                                                                                                                                                                                                                 }
8788                                                                                                                                                                                                 }
8789                                                                                                                                                                                                 player[i].CheckKick();
8790                                                                                                                                                                                                 player[k].CheckKick();
8791                                                                                                                                                                         }
8792                                                                                                                                                                 }
8793                                                                 }
8794                                                         }
8795
8796                                                         for(k=0;k<numplayers;k++){
8797                                                                 for(i=k;i<numplayers;i++){
8798                                                                         if(i==k)i++;
8799                                                                         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))){
8800                                                                                 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)){
8801                                                                                         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)){
8802                                                                                                 player[i].victim=&player[k];
8803                                                                                                 player[i].targetanimation=jumpreversedanim;
8804                                                                                                 player[i].currentanimation=jumpreversedanim;
8805                                                                                                 player[k].currentanimation=jumpreversalanim;
8806                                                                                                 player[k].targetanimation=jumpreversalanim;
8807                                                                                                 player[i].targettilt2=0;
8808                                                                                                 player[i].currentframe=0;
8809                                                                                                 player[i].targetframe=1;
8810                                                                                                 player[k].currentframe=0;
8811                                                                                                 player[k].targetframe=1;
8812                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8813                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8814                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8815                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8816                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8817                                                                                                         player[k].currentframe=1;
8818                                                                                                         player[k].targetframe=2;
8819                                                                                                         player[i].currentframe=1;
8820                                                                                                         player[i].targetframe=2;
8821                                                                                                 }
8822                                                                                                 player[k].targettilt2=0;
8823                                                                                                 player[i].target=0;
8824                                                                                                 player[i].velocity=0;
8825                                                                                                 player[k].velocity=0;
8826                                                                                                 player[k].oldcoords=player[k].coords;
8827                                                                                                 player[i].coords=player[k].coords;
8828                                                                                                 player[k].targetrotation=player[i].targetrotation;
8829                                                                                                 player[k].rotation=player[i].targetrotation;
8830                                                                                                 player[k].victim=&player[i];
8831                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8832                                                                                         }
8833                                                                                         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)){
8834                                                                                                 player[k].victim=&player[i];
8835                                                                                                 player[k].targetanimation=jumpreversedanim;
8836                                                                                                 player[k].currentanimation=jumpreversedanim;
8837                                                                                                 player[i].currentanimation=jumpreversalanim;
8838                                                                                                 player[i].targetanimation=jumpreversalanim;
8839                                                                                                 player[k].targettilt2=0;
8840                                                                                                 player[i].targettilt2=0;
8841                                                                                                 player[k].currentframe=0;
8842                                                                                                 player[k].targetframe=1;
8843                                                                                                 player[i].currentframe=0;
8844                                                                                                 player[i].targetframe=1;
8845                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8846                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8847                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8848                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8849                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8850                                                                                                         player[k].currentframe=1;
8851                                                                                                         player[k].targetframe=2;
8852                                                                                                         player[i].currentframe=1;
8853                                                                                                         player[i].targetframe=2;
8854                                                                                                 }
8855                                                                                                 player[k].target=0;
8856                                                                                                 player[k].velocity=0;
8857                                                                                                 player[i].velocity=0;
8858                                                                                                 player[i].oldcoords=player[i].coords;
8859                                                                                                 player[k].coords=player[i].coords;
8860                                                                                                 player[i].targetrotation=player[k].targetrotation;
8861                                                                                                 player[i].rotation=player[k].targetrotation;
8862                                                                                                 player[i].victim=&player[k];
8863                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8864                                                                                         }
8865                                                                                 }
8866                                                                         }
8867                                                                 }
8868                                                         }
8869
8870                                                         for(k=0;k<numplayers;k++)
8871                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8872
8873
8874                                                         //pile
8875                                                         /*
8876                                                         XYZ tempdiff;
8877                                                         XYZ tempoldpos;
8878                                                         XYZ temp1,temp2;
8879                                                         bool isgood;
8880                                                         static float checkdelay;
8881                                                         checkdelay-=multiplier;
8882                                                         int m;
8883                                                         static bool checkedcoll[maxplayers][maxplayers];
8884                                                         static bool above[maxplayers];
8885
8886                                                         for(i=0;i<maxplayers;i++){
8887                                                         for(j=0;j<maxplayers;j++){
8888                                                         checkedcoll[i][j]=0;
8889                                                         }
8890                                                         }
8891
8892                                                         if(numplayers>1&&checkdelay<=0){
8893                                                         checkdelay=.015;
8894                                                         for(k=0;k<numplayers;k++){
8895                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8896
8897                                                         for(i=k;i<numplayers;i++){
8898                                                         if(i==k)i++;
8899                                                         if(i<numplayers)
8900                                                         if(!checkedcoll[i][k]){
8901                                                         checkedcoll[i][k]=1;
8902                                                         checkedcoll[k][i]=1;
8903                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8904                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8905                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8906                                                         if(player[i].coords.y>player[k].coords.y-3)
8907                                                         if(player[i].coords.y<player[k].coords.y+3)
8908                                                         if(player[i].coords.x>player[k].coords.x-3)
8909                                                         if(player[i].coords.x<player[k].coords.x+3)
8910                                                         if(player[i].coords.z>player[k].coords.z-3)
8911                                                         if(player[i].coords.z<player[k].coords.z+3)
8912                                                         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)){
8913                                                         int stuck,moving;
8914                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8915                                                         stuck=i;
8916                                                         moving=k;
8917                                                         }
8918                                                         else
8919                                                         {
8920                                                         moving=i;
8921                                                         stuck=k;
8922                                                         }
8923                                                         isgood=1;
8924
8925                                                         if(isgood){
8926                                                         above[moving]=stuck;
8927                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8928                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8929                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8930                                                         {
8931                                                         player[moving].skeleton.joints[l].position.y+=.003;
8932                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8933
8934                                                         }
8935                                                         }
8936                                                         }
8937                                                         }
8938                                                         }
8939                                                         }
8940                                                         }
8941                                                         }
8942                                                         }
8943
8944                                                         */
8945
8946                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
8947                                                                 texturesizetogglekeydown=0;
8948                                                         }
8949
8950                                                         for(k=0;k<numplayers;k++){
8951                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8952                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8953                                                                                 player[k].DoDamage(1000);
8954                                                                         }
8955                                                                 }
8956                                                         }
8957
8958                                                         static bool respawnkeydown;
8959                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
8960                                                                 targetlevel=whichlevel;
8961                                                                 loading=1;
8962                                                                 leveltime=5;
8963                                                         }
8964                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
8965                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
8966
8967
8968
8969
8970                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
8971                                                                 targetlevel++;
8972                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
8973                                                                 loading=1;
8974                                                                 leveltime=5;
8975                                                                 slomotogglekeydown=1;
8976                                                         }
8977
8978                                                         /*
8979                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
8980                                                         //Respawn
8981                                                         FSOUND_SetPaused(channels[whooshsound], TRUE);
8982                                                         changedelay=0;
8983                                                         for(k=0;k<numplayers;k++){
8984                                                         player[k].dead=0;
8985                                                         player[k].damage=0;
8986                                                         player[k].permanentdamage=0;
8987                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
8988                                                         player[k].aitype=passivetype;
8989                                                         }
8990                                                         player[0].aitype=playercontrolled;
8991                                                         }
8992                                                         */
8993
8994                                                         static bool movekey;
8995                                                         static bool connected;
8996                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
8997                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
8998                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
8999                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
9000                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
9001                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
9002
9003                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
9004
9005                 for(int i=0;i<numplayers;i++){  
9006                                                                 if(!player[i].skeleton.free){
9007                                                                         oldtargetrotation=player[i].targetrotation;
9008                                                                         if(i==0&&indialogue==-1){
9009                                                                                 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){
9010                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
9011                                                                                         if(cameramode)player[0].targetrotation=0;
9012                                                                                 }
9013
9014                                                                                 facing=0;
9015                                                                                 facing.z=-1;
9016
9017                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9018                                                                                 if(cameramode){facing=flatfacing;}
9019                                                                                 else{
9020                                                                                         facing=DoRotation(facing,-rotation2,0,0);
9021                                                                                         facing=DoRotation(facing,0,0-rotation,0);
9022                                                                                 }
9023
9024                                                                                 player[0].lookrotation=-rotation;
9025
9026                                                                                 player[i].targetheadrotation=rotation;
9027                                                                                 player[i].targetheadrotation2=rotation2;                        
9028                                                                         }
9029                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
9030                                                                                 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){
9031                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
9032                                                                                 }
9033
9034                                                                                 facing=0;
9035                                                                                 facing.z=-1;
9036
9037                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9038
9039                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
9040                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
9041
9042                                                                                 player[i].targetheadrotation=player[i].lookrotation;
9043                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;                  
9044                                                                         }
9045                                                                         if(indialogue!=-1){
9046                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
9047                                                                                 Normalise(&rotatetarget);
9048                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
9049                                                                                 player[i].targetheadrotation*=360/6.28;
9050                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9051
9052                                                                                 player[i].targetheadrotation*=-1;
9053                                                                                 player[i].targetheadrotation+=180;
9054                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9055                                                                         }
9056
9057                                                                         bool pause;
9058
9059                                                                         if(leveltime<.5)
9060                                                                                 numenvsounds=0;
9061
9062                                                                         player[i].avoidsomething=0;
9063
9064                                                                         for(j=0;j<objects.numobjects;j++){
9065                                                                                 if(objects.onfire[j]){
9066                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
9067                                                                                         {
9068                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
9069                                                                                                         player[i].collided=0;
9070                                                                                                         player[i].avoidcollided=1;
9071                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9072                                                                                                                 player[i].avoidwhere=objects.position[j];
9073                                                                                                 }
9074                                                                                         }
9075                                                                                 }
9076                                                                         }
9077
9078                                                                         //Add avoidwhere to players
9079
9080                                                                         for(j=0;j<numplayers;j++){
9081                                                                                 if(player[j].onfire){
9082                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
9083                                                                                         {
9084                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
9085                                                                                                         player[i].collided=0;
9086                                                                                                         player[i].avoidcollided=1;
9087                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9088                                                                                                                 player[i].avoidwhere=objects.position[j];
9089                                                                                                 }
9090                                                                                         }
9091                                                                                 }
9092                                                                         }
9093
9094                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
9095                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
9096                                                                                 player[i].jumpclimb=0;
9097                                                                                 //AI
9098                                                                                 if(editorenabled)player[i].stunned=1;
9099
9100                                                                                 player[i].pause=0;
9101                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
9102                                                                                 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;
9103
9104                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
9105                                                                                 player[i].forwardkeydown=0;
9106                                                                                 player[i].leftkeydown=0;
9107                                                                                 player[i].backkeydown=0;
9108                                                                                 player[i].rightkeydown=0;
9109                                                                                 player[i].crouchkeydown=0;
9110                                                                                 player[i].attackkeydown=0;
9111                                                                                 player[i].jumpkeydown=0;
9112                                                                                 player[i].throwkeydown=0;
9113                                                                                 }*/
9114
9115                                                                                 if(player[i].aitype==pathfindtype){
9116                                                                                         if(player[i].finalpathfindpoint==-1){
9117                                                                                                 float closestdistance;
9118                                                                                                 float tempdist;
9119                                                                                                 int closest;
9120                                                                                                 XYZ colpoint;
9121                                                                                                 closest=-1;
9122                                                                                                 closestdistance=-1;
9123                                                                                                 for(j=0;j<numpathpoints;j++){
9124                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
9125                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
9126                                                                                                                 closest=j;
9127                                                                                                                 player[i].finaltarget=pathpoint[j];
9128                                                                                                         }
9129                                                                                                 }
9130                                                                                                 player[i].finalpathfindpoint=closest;
9131                                                                                                 for(j=0;j<numpathpoints;j++){
9132                                                                                                         if(numpathpointconnect[j])
9133                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9134                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9135                                                                                                                         if(tempdist*tempdist<closestdistance){
9136                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9137                                                                                                                                         closestdistance=tempdist*tempdist;
9138                                                                                                                                         closest=j;
9139                                                                                                                                         player[i].finaltarget=colpoint;
9140                                                                                                                                 }
9141                                                                                                                         }
9142                                                                                                                 }
9143                                                                                                 }
9144                                                                                                 player[i].finalpathfindpoint=closest;
9145
9146                                                                                         }
9147                                                                                         if(player[i].targetpathfindpoint==-1){
9148                                                                                                 float closestdistance;
9149                                                                                                 float tempdist;
9150                                                                                                 int closest;
9151                                                                                                 XYZ colpoint;
9152                                                                                                 closest=-1;
9153                                                                                                 closestdistance=-1;
9154                                                                                                 if(player[i].lastpathfindpoint==-1){
9155                                                                                                         for(j=0;j<numpathpoints;j++){
9156                                                                                                                 if(j!=player[i].lastpathfindpoint)
9157                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
9158                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
9159                                                                                                                                 closest=j;
9160                                                                                                                         }
9161                                                                                                         }
9162                                                                                                         player[i].targetpathfindpoint=closest;
9163                                                                                                         for(j=0;j<numpathpoints;j++){
9164                                                                                                                 if(j!=player[i].lastpathfindpoint)
9165                                                                                                                         if(numpathpointconnect[j])
9166                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9167                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9168                                                                                                                                         if(tempdist*tempdist<closestdistance){
9169                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9170                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
9171                                                                                                                                                         closestdistance=tempdist*tempdist;
9172                                                                                                                                                         closest=j;
9173                                                                                                                                                         //}
9174                                                                                                                                                 }
9175                                                                                                                                         }
9176                                                                                                                                 }
9177                                                                                                         }
9178                                                                                                         player[i].targetpathfindpoint=closest;
9179                                                                                                 }
9180                                                                                                 else
9181                                                                                                 {
9182                                                                                                         for(j=0;j<numpathpoints;j++){
9183                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
9184                                                                                                                 {
9185                                                                                                                         connected=0;
9186                                                                                                                         if(numpathpointconnect[j])
9187                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9188                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
9189                                                                                                                                 }
9190                                                                                                                                 if(!connected)
9191                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
9192                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
9193                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
9194                                                                                                                                                 }
9195                                                                                                                                                 if(connected){
9196                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
9197                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
9198                                                                                                                                                                 closestdistance=tempdist;
9199                                                                                                                                                                 closest=j;
9200                                                                                                                                                         }
9201                                                                                                                                                 }
9202                                                                                                                 }
9203                                                                                                         }
9204                                                                                                         player[i].targetpathfindpoint=closest;
9205                                                                                                 }
9206                                                                                         }
9207                                                                                         player[i].losupdatedelay-=multiplier;
9208
9209                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
9210                                                                                         Normalise(&rotatetarget);
9211                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9212                                                                                         player[i].targetrotation*=360/6.28;
9213                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9214                                                                                         player[i].lookrotation=player[i].targetrotation;
9215                                                                                         //player[i].aiupdatedelay=.05;
9216
9217                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
9218                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9219                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9220                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9221                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
9222                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9223                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9224                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9225                                                                                                 player[i].targetpathfindpoint=-1;
9226                                                                                         }
9227                                                                                         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){
9228                                                                                                 player[i].aitype=passivetype;
9229                                                                                         }
9230
9231                                                                                         player[i].forwardkeydown=1;
9232                                                                                         player[i].leftkeydown=0;
9233                                                                                         player[i].backkeydown=0;
9234                                                                                         player[i].rightkeydown=0;
9235                                                                                         player[i].crouchkeydown=0;
9236                                                                                         player[i].attackkeydown=0;
9237                                                                                         player[i].throwkeydown=0;
9238
9239                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9240
9241                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9242                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9243
9244                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9245                                                                                                 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))
9246                                                                                                         player[i].aitype=attacktypecutoff;
9247                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9248                                                                                                         player[i].aitype=attacktypecutoff;
9249
9250                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9251                                                                                                         player[i].losupdatedelay=.2;
9252                                                                                                         for(j=0;j<numplayers;j++){
9253                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9254                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9255                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9256                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9257                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9258                                                                                                                                                         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)){
9259                                                                                                                                                                 player[i].aitype=searchtype;
9260                                                                                                                                                                 player[i].lastchecktime=12;
9261                                                                                                                                                                 player[i].lastseen=player[j].coords;
9262                                                                                                                                                                 player[i].lastseentime=12;
9263                                                                                                                                                         }
9264                                                                                                                 }
9265                                                                                                         }
9266                                                                                                 }
9267                                                                                         }       
9268                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9269                                                                                                 if(player[i].creature!=wolftype){
9270                                                                                                         player[i].stunned=.6;
9271                                                                                                         player[i].surprised=.6;
9272                                                                                                 }
9273                                                                                         }
9274                                                                                 }
9275
9276                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9277                                                                                         player[i].howactive=typeactive;
9278                                                                                 }
9279
9280                                                                                 if(player[i].aitype==passivetype){
9281                                                                                         player[i].aiupdatedelay-=multiplier;
9282                                                                                         player[i].losupdatedelay-=multiplier;
9283                                                                                         player[i].lastseentime+=multiplier;
9284                                                                                         player[i].pausetime-=multiplier;
9285                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9286
9287                                                                                         if(player[i].aiupdatedelay<0){
9288                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9289                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9290                                                                                                         Normalise(&rotatetarget);
9291                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9292                                                                                                         player[i].targetrotation*=360/6.28;
9293                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9294                                                                                                         player[i].lookrotation=player[i].targetrotation;
9295                                                                                                         player[i].aiupdatedelay=.05;
9296
9297                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9298                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9299                                                                                                                 player[i].waypoint++;
9300                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9301
9302                                                                                                         }
9303                                                                                                 }                       
9304
9305                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9306                                                                                                 else player[i].forwardkeydown=0;
9307                                                                                                 player[i].leftkeydown=0;
9308                                                                                                 player[i].backkeydown=0;
9309                                                                                                 player[i].rightkeydown=0;
9310                                                                                                 player[i].crouchkeydown=0;
9311                                                                                                 player[i].attackkeydown=0;
9312                                                                                                 player[i].throwkeydown=0;
9313
9314                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9315                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9316                                                                                                         else{
9317                                                                                                                 XYZ leftpos,rightpos;
9318                                                                                                                 float leftdist,rightdist;
9319                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9320                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9321                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9322                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9323                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9324                                                                                                                 else player[i].targetrotation-=90;
9325                                                                                                         }
9326                                                                                                 }
9327                                                                                         }                       
9328                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9329                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9330
9331
9332                                                                                         if(!editorenabled){
9333                                                                                                 if(player[i].howactive<typesleeping)
9334                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9335                                                                                                                 for(j=0;j<numenvsounds;j++){
9336                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9337                                                                                                                                 player[i].aitype=attacktypecutoff;
9338                                                                                                                         }
9339                                                                                                                 }
9340
9341                                                                                                                 if(player[i].howactive==typesleeping)
9342                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9343                                                                                                                                 for(j=0;j<numenvsounds;j++){
9344                                                                                                                                         if(envsoundvol[j]>14)
9345                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9346                                                                                                                                                         player[i].aitype=attacktypecutoff;
9347                                                                                                                                                 }
9348                                                                                                                                 }
9349
9350                                                                                                                                 if(player[i].aitype!=passivetype){
9351                                                                                                                                         if(player[i].howactive==typesleeping){
9352                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9353                                                                                                                                                 player[i].targetframe=0;
9354                                                                                                                                                 player[i].target=0;
9355                                                                                                                                         }
9356
9357                                                                                                                                         player[i].howactive=typeactive;
9358                                                                                                                                 }
9359                                                                                         }                       
9360
9361                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9362                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9363                                                                                                         player[i].aitype=attacktypecutoff;
9364                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9365                                                                                                         player[i].aitype=attacktypecutoff;
9366
9367                                                                                                 if(player[i].creature==wolftype){
9368                                                                                                         XYZ windsmell;
9369                                                                                                         float smelldistance;
9370                                                                                                         smelldistance=50;
9371                                                                                                         for(j=0;j<numplayers;j++){
9372                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9373                                                                                                                         if(j==0&&player[j].num_weapons>0){
9374                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9375                                                                                                                                 if(player[j].num_weapons==2)
9376                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9377                                                                                                                         }
9378                                                                                                                         if(j!=0){
9379                                                                                                                                 smelldistance=100;
9380                                                                                                                         }
9381                                                                                                                         windsmell=windvector;
9382                                                                                                                         Normalise(&windsmell);
9383                                                                                                                         windsmell=windsmell*2+player[j].coords;
9384                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9385                                                                                                                                 player[i].aitype=attacktypecutoff;
9386                                                                                                                 }
9387                                                                                                         }
9388                                                                                                 }
9389
9390                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9391                                                                                                         player[i].losupdatedelay=.2;
9392                                                                                                         for(j=0;j<numplayers;j++){
9393                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9394                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9395                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9396                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9397                                                                                                                                                 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)){
9398                                                                                                                                                         player[i].lastseentime-=.2;
9399                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9400                                                                                                                                                         else player[i].lastseentime-=.6;                                                                
9401                                                                                                                                                 }
9402                                                                                                                                                 if(player[i].lastseentime<=0){
9403                                                                                                                                                         player[i].aitype=searchtype;
9404                                                                                                                                                         player[i].lastchecktime=12;
9405                                                                                                                                                         player[i].lastseen=player[j].coords;
9406                                                                                                                                                         player[i].lastseentime=12;
9407                                                                                                                                                 }
9408                                                                                                                 }
9409                                                                                                         }
9410                                                                                                 }
9411                                                                                         }
9412                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9413                                                                                                 if(player[i].creature!=wolftype){
9414                                                                                                         player[i].stunned=.6;
9415                                                                                                         player[i].surprised=.6;
9416                                                                                                 }
9417                                                                                                 if(player[i].creature==wolftype){
9418                                                                                                         player[i].stunned=.47;
9419                                                                                                         player[i].surprised=.47;
9420                                                                                                 }
9421                                                                                                 numseen++;
9422                                                                                         }
9423                                                                                 }               
9424
9425                                                                                 if(player[i].aitype==searchtype){
9426                                                                                         player[i].aiupdatedelay-=multiplier;
9427                                                                                         player[i].losupdatedelay-=multiplier;
9428                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9429                                                                                         player[i].lastchecktime-=multiplier;
9430
9431                                                                                         if(player[i].isRun()&&!player[i].onground){
9432                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9433                                                                                                         test2=player[i].coords+player[i].facing;
9434                                                                                                         test2.y+=5;
9435                                                                                                         test=player[i].coords+player[i].facing;
9436                                                                                                         test.y-=10;
9437                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9438                                                                                                         if(j==-1)j=checkcollide(test2,test);
9439                                                                                                         if(j==-1){
9440                                                                                                                 player[i].velocity=0;
9441                                                                                                                 player[i].targetanimation=player[i].getStop();
9442                                                                                                                 player[i].targetframe=0;
9443                                                                                                                 player[i].target=0;
9444                                                                                                                 player[i].targetrotation+=180;
9445                                                                                                                 player[i].stunned=.5;
9446                                                                                                                 //player[i].aitype=passivetype;
9447                                                                                                                 player[i].aitype=pathfindtype;
9448                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9449                                                                                                                 player[i].finalpathfindpoint=-1;
9450                                                                                                                 player[i].targetpathfindpoint=-1;
9451                                                                                                                 player[i].lastpathfindpoint=-1;
9452                                                                                                                 player[i].lastpathfindpoint2=-1;
9453                                                                                                                 player[i].lastpathfindpoint3=-1;
9454                                                                                                                 player[i].lastpathfindpoint4=-1;
9455                                                                                                         }
9456                                                                                                         else player[i].laststanding=j;
9457                                                                                                 }
9458                                                                                         }       
9459                                                                                         if(player[i].aiupdatedelay<0){
9460                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9461                                                                                                 Normalise(&rotatetarget);
9462                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9463                                                                                                 player[i].targetrotation*=360/6.28;
9464                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9465                                                                                                 player[i].lookrotation=player[i].targetrotation;
9466                                                                                                 player[i].aiupdatedelay=.05;
9467                                                                                                 player[i].forwardkeydown=1;
9468
9469                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9470                                                                                                         player[i].forwardkeydown=0;
9471                                                                                                         player[i].aiupdatedelay=1;
9472                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9473                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9474                                                                                                         player[i].lastchecktime=3;
9475                                                                                                 }
9476
9477                                                                                                 player[i].leftkeydown=0;
9478                                                                                                 player[i].backkeydown=0;
9479                                                                                                 player[i].rightkeydown=0;
9480                                                                                                 player[i].crouchkeydown=0;
9481                                                                                                 player[i].attackkeydown=0;
9482                                                                                                 player[i].throwkeydown=0;
9483
9484                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9485                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9486                                                                                                         else{
9487                                                                                                                 XYZ leftpos,rightpos;
9488                                                                                                                 float leftdist,rightdist;
9489                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9490                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9491                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9492                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9493                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9494                                                                                                                 else player[i].targetrotation-=90;
9495                                                                                                         }
9496                                                                                                 }
9497                                                                                         }
9498                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9499                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9500
9501                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9502                                                                                                 for(j=0;j<numenvsounds;j++){
9503                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9504                                                                                                                 player[i].aitype=attacktypecutoff;
9505                                                                                                         }
9506                                                                                                 }
9507
9508                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9509                                                                                                         player[i].losupdatedelay=.2;
9510                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9511                                                                                                         {player[i].aitype=attacktypecutoff;
9512                                                                                                         player[i].lastseentime=1;}
9513                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9514                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9515                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9516                                                                                                                                 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)){
9517                                                                                                                                         player[i].aitype=attacktypecutoff;
9518                                                                                                                                         player[i].lastseentime=1;
9519                                                                                                                                 }
9520                                                                                                 }
9521                                                                                                 if(player[i].lastseentime<0){
9522                                                                                                         //player[i].aitype=passivetype;
9523                                                                                                         numescaped++;
9524                                                                                                         player[i].aitype=pathfindtype;
9525                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9526                                                                                                         player[i].finalpathfindpoint=-1;
9527                                                                                                         player[i].targetpathfindpoint=-1;
9528                                                                                                         player[i].lastpathfindpoint=-1;
9529                                                                                                         player[i].lastpathfindpoint2=-1;
9530                                                                                                         player[i].lastpathfindpoint3=-1;
9531                                                                                                         player[i].lastpathfindpoint4=-1;
9532                                                                                                 }
9533                                                                                 }
9534
9535                                                                                 if(player[i].aitype!=gethelptype){
9536                                                                                         player[i].runninghowlong=0;
9537                                                                                 }
9538
9539                                                                                 if(player[i].aitype==gethelptype){
9540                                                                                         player[i].runninghowlong+=multiplier;
9541                                                                                         player[i].aiupdatedelay-=multiplier;
9542
9543                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9544                                                                                                 player[i].aiupdatedelay=.2;
9545
9546                                                                                                 int closest;
9547                                                                                                 float closestdist;
9548                                                                                                 closest=-1;
9549                                                                                                 closestdist=-1;
9550                                                                                                 float distance;
9551
9552                                                                                                 if(!player[i].ally){
9553                                                                                                         for(j=0;j<numplayers;j++){
9554                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9555                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9556                                                                                                                         if(closestdist==-1||distance<closestdist){
9557                                                                                                                                 closestdist=distance;
9558                                                                                                                                 closest=j;
9559                                                                                                                         }
9560                                                                                                                         closest=j;
9561                                                                                                                 }
9562                                                                                                         }
9563                                                                                                         if(closest!=-1)player[i].ally=closest;
9564                                                                                                         else player[i].ally=0;
9565                                                                                                         player[i].lastseen=player[0].coords;
9566                                                                                                         player[i].lastseentime=12;
9567                                                                                                 }
9568
9569
9570                                                                                                 player[i].lastchecktime=12;
9571                                                                                                 //player[i].lastseentime-=.5;
9572
9573                                                                                                 facing=player[i].coords;
9574                                                                                                 flatfacing=player[player[i].ally].coords;
9575                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9576                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9577                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9578                                                                                                         player[i].lastseentime-=.1;
9579
9580                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9581                                                                                                         player[i].aitype=searchtype;
9582                                                                                                         player[i].lastseentime=12;
9583                                                                                                 }
9584
9585                                                                                                 if(player[i].ally>0){
9586                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9587                                                                                                         Normalise(&rotatetarget);
9588                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9589                                                                                                         player[i].targetrotation*=360/6.28;
9590                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9591                                                                                                         player[i].lookrotation=player[i].targetrotation;
9592                                                                                                         player[i].aiupdatedelay=.05;
9593                                                                                                         player[i].forwardkeydown=1;                                     
9594
9595                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9596                                                                                                                 player[i].aitype=searchtype;
9597                                                                                                                 player[i].lastseentime=12;
9598                                                                                                                 player[player[i].ally].aitype=searchtype;
9599                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9600                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9601                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9602                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9603                                                                                                                 }
9604                                                                                                         }
9605
9606                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9607                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9608                                                                                                                 else{
9609                                                                                                                         XYZ leftpos,rightpos;
9610                                                                                                                         float leftdist,rightdist;
9611                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9612                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9613                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9614                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9615                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9616                                                                                                                         else player[i].targetrotation-=90;
9617                                                                                                                 }
9618                                                                                                         }
9619                                                                                                 }
9620
9621                                                                                                 player[i].leftkeydown=0;
9622                                                                                                 player[i].backkeydown=0;
9623                                                                                                 player[i].rightkeydown=0;
9624                                                                                                 player[i].crouchkeydown=0;
9625                                                                                                 player[i].attackkeydown=0;
9626                                                                                         }
9627                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9628                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9629                                                                                 }
9630
9631                                                                                 if(player[i].aitype==getweapontype){
9632                                                                                         player[i].aiupdatedelay-=multiplier;
9633                                                                                         player[i].lastchecktime-=multiplier;
9634
9635                                                                                         if(player[i].aiupdatedelay<0){
9636                                                                                                 player[i].aiupdatedelay=.2;
9637
9638                                                                                                 int closest;
9639                                                                                                 float closestdist;
9640                                                                                                 closest=-1;
9641                                                                                                 closestdist=-1;
9642                                                                                                 float distance;
9643
9644                                                                                                 if(player[i].ally<0){
9645                                                                                                         for(j=0;j<weapons.numweapons;j++){
9646                                                                                                                 if(weapons.owner[j]==-1){
9647                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9648                                                                                                                         if(closestdist==-1||distance<closestdist){
9649                                                                                                                                 closestdist=distance;
9650                                                                                                                                 closest=j;
9651                                                                                                                         }
9652                                                                                                                         closest=j;
9653                                                                                                                 }
9654                                                                                                         }
9655                                                                                                         if(closest!=-1)player[i].ally=closest;
9656                                                                                                         else player[i].ally=-1;
9657                                                                                                 }
9658
9659                                                                                                 player[i].lastseentime=12;
9660
9661                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9662                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9663                                                                                                                 player[i].aitype=attacktypecutoff;
9664                                                                                                                 player[i].lastseentime=1;
9665                                                                                                         }                                       
9666                                                                                                         if(!player[0].dead)
9667                                                                                                                 if(player[i].ally>=0){
9668                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9669                                                                                                                                 player[i].aitype=attacktypecutoff;
9670                                                                                                                                 player[i].lastseentime=1;
9671                                                                                                                         }
9672                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9673                                                                                                                         Normalise(&rotatetarget);
9674                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9675                                                                                                                         player[i].targetrotation*=360/6.28;
9676                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9677                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9678                                                                                                                         player[i].aiupdatedelay=.05;
9679                                                                                                                         player[i].forwardkeydown=1;                                     
9680
9681
9682                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9683                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9684                                                                                                                                 else{
9685                                                                                                                                         XYZ leftpos,rightpos;
9686                                                                                                                                         float leftdist,rightdist;
9687                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9688                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9689                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9690                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9691                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9692                                                                                                                                         else player[i].targetrotation-=90;
9693                                                                                                                                 }
9694                                                                                                                         }
9695                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9696                                                                                                                         if(abs(Random()%6)){
9697                                                                                                                         player[i].crouchkeydown=1;
9698                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9699                                                                                                                         if(player[i].isRun()){
9700                                                                                                                         player[i].targetframe=0;
9701                                                                                                                         player[i].target=0;
9702                                                                                                                         player[i].targetanimation=sneakanim;
9703                                                                                                                         }
9704                                                                                                                         }
9705                                                                                                                         else player[i].forwardkeydown=0;
9706                                                                                                                         }
9707                                                                                                                         else player[i].crouchkeydown=0;
9708                                                                                                                         }
9709                                                                                                                         else player[i].crouchkeydown=0;*/
9710                                                                                                                 }
9711
9712                                                                                                                 player[i].leftkeydown=0;
9713                                                                                                                 player[i].backkeydown=0;
9714                                                                                                                 player[i].rightkeydown=0;
9715                                                                                                                 player[i].attackkeydown=0;
9716                                                                                                                 player[i].throwkeydown=1;
9717                                                                                                                 player[i].crouchkeydown=0;      
9718                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9719                                                                                                                 player[i].drawkeydown=0;
9720                                                                                         }
9721                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9722                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9723                                                                                 }
9724
9725                                                                                 if(player[i].aitype==attacktypecutoff){
9726                                                                                         player[i].aiupdatedelay-=multiplier;
9727                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9728                                                                                                 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)){
9729                                                                                                         player[i].attackkeydown=0;
9730                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9731                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9732                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9733                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9734                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9735                                                                                                                                 else player[i].targetanimation=rollanim;
9736                                                                                                                                 player[i].target=0;
9737                                                                                                                                 player[i].targetframe=0;
9738                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9739                                                                                                                                 player[i].wentforweapon=0;
9740                                                                                                                         }
9741                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9742                                                                                                                                 player[i].targetanimation=flipanim;
9743                                                                                                                                 player[i].target=0;
9744                                                                                                                                 player[i].targetframe=0;
9745                                                                                                                         }
9746                                                                                                                 }
9747                                                                                                         }
9748                                                                                                         player[i].forwardkeydown=0;
9749                                                                                                         player[i].aiupdatedelay=.02;
9750                                                                                                 }
9751                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9752                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9753                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9754                                                                                                 }
9755                                                                                                 if(player[i].wentforweapon<3)
9756                                                                                                         for(j=0;j<weapons.numweapons;j++){
9757                                                                                                                 if(player[i].creature!=wolftype)
9758                                                                                                                         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){
9759                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9760                                                                                                                                         player[i].wentforweapon++;
9761                                                                                                                                         player[i].lastchecktime=6;
9762                                                                                                                                         player[i].aitype=getweapontype;
9763                                                                                                                                         player[i].ally=-1;
9764                                                                                                                                 }
9765                                                                                                                         }
9766                                                                                                         }
9767                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9768                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9769                                                                                                                         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)))){
9770                                                                                                                                 player[i].crouchkeydown=1;
9771                                                                                                                         }
9772                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9773                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9774                                                                                                                                         test2=player[i].coords+player[i].facing;
9775                                                                                                                                         test2.y+=5;
9776                                                                                                                                         test=player[i].coords+player[i].facing;
9777                                                                                                                                         test.y-=10;
9778                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9779                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9780                                                                                                                                         if(j==-1){
9781                                                                                                                                                 player[i].velocity=0;
9782                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9783                                                                                                                                                 player[i].targetframe=0;
9784                                                                                                                                                 player[i].target=0;
9785                                                                                                                                                 player[i].targetrotation+=180;
9786                                                                                                                                                 player[i].stunned=.5;
9787                                                                                                                                                 //player[i].aitype=passivetype;
9788                                                                                                                                                 player[i].aitype=pathfindtype;
9789                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9790                                                                                                                                                 player[i].finalpathfindpoint=-1;
9791                                                                                                                                                 player[i].targetpathfindpoint=-1;
9792                                                                                                                                                 player[i].lastpathfindpoint=-1;
9793                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9794                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9795                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9796                                                                                                                                         }
9797                                                                                                                                         else player[i].laststanding=j;
9798                                                                                                                                 }
9799                                                                                                                         }
9800                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9801                                                                                                                                 player[i].aitype=pathfindtype;
9802                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9803                                                                                                                                 player[i].finalpathfindpoint=-1;
9804                                                                                                                                 player[i].targetpathfindpoint=-1;
9805                                                                                                                                 player[i].lastpathfindpoint=-1;
9806                                                                                                                                 player[i].lastpathfindpoint2=-1;
9807                                                                                                                                 player[i].lastpathfindpoint3=-1;
9808                                                                                                                                 player[i].lastpathfindpoint4=-1;
9809                                                                                                                         }       
9810                                                                                                                         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){
9811                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9812                                                                                                                                 else player[i].drawkeydown=0;
9813                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9814                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9815                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9816                                                                                                                                         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;
9817                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9818                                                                                                                                 Normalise(&rotatetarget);
9819                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9820                                                                                                                                 player[i].targetrotation*=360/6.28;
9821                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9822                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9823                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9824
9825                                                                                                                                 oldkey=player[i].forwardkeydown;
9826                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9827                                                                                                                                 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;
9828                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9829                                                                                                                                 else player[i].forwardkeydown=0;
9830                                                                                                                                 if(player[0].dead){
9831                                                                                                                                         player[i].forwardkeydown=0;
9832                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9833                                                                                                                                         if(Random()%100==0){
9834                                                                                                                                                 player[i].aitype=pathfindtype;
9835                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9836                                                                                                                                                 player[i].finalpathfindpoint=-1;
9837                                                                                                                                                 player[i].targetpathfindpoint=-1;
9838                                                                                                                                                 player[i].lastpathfindpoint=-1;
9839                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9840                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9841                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9842                                                                                                                                         }
9843                                                                                                                                 }
9844                                                                                                                                 player[i].leftkeydown=0;
9845                                                                                                                                 player[i].backkeydown=0;
9846                                                                                                                                 player[i].rightkeydown=0;
9847                                                                                                                                 player[i].crouchkeydown=0;
9848                                                                                                                                 player[i].throwkeydown=0;
9849
9850                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9851                                                                                                                                 /*for(j=0;j<numplayers;j++){
9852                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9853                                                                                                                                 player[i].crouchkeydown=1;
9854                                                                                                                                 }
9855                                                                                                                                 }*/
9856                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9857                                                                                                                                 else player[i].attackkeydown=0;
9858                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9859                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9860                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9861                                                                                                                                 player[i].attackkeydown=0;
9862                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9863                                                                                                                                 player[i].forwardkeydown=0;
9864                                                                                                                                 player[i].aiupdatedelay=.02;
9865                                                                                                                                 }*/
9866
9867                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9868                                                                                                                                         target=-2;
9869                                                                                                                                         for(j=0;j<numplayers;j++){
9870                                                                                                                                                 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)){
9871                                                                                                                                                         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))))){
9872                                                                                                                                                                 if(target>=0)target=-1;
9873                                                                                                                                                                 else target=j;
9874                                                                                                                                                         }
9875                                                                                                                                                 }
9876                                                                                                                                         }
9877                                                                                                                                         if(target>=0)player[target].Reverse();
9878                                                                                                                                 }
9879
9880                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9881                                                                                                                                 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;
9882                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9883                                                                                                                                         player[0].jumpkeydown=0;
9884                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9885                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9886                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9887
9888                                                                                                                                 if(tutoriallevel==1){
9889                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9890                                                                                                                                 }
9891
9892
9893                                                                                                                                 facing=player[i].coords;
9894                                                                                                                                 flatfacing=player[0].coords;
9895                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9896                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9897                                                                                                                                 if(player[i].occluded>=2)
9898                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9899                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9900                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9901                                                                                                                                                         player[i].aitype=searchtype;
9902                                                                                                                                                         player[i].lastchecktime=12;
9903                                                                                                                                                         player[i].lastseen=player[0].coords;
9904                                                                                                                                                         player[i].lastseentime=12;
9905                                                                                                                                                 }
9906                                                                                                                                         }
9907                                                                                                                                         else player[i].lastseentime=1;
9908                                                                                                                         }
9909                                                                                 }
9910                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9911                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9912                                                                                                 test=player[0].coords;
9913                                                                                                 test.y-=40;
9914                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9915                                                                                         }
9916                                                                                 }
9917                                                                                 // NOTE: Ask about logic of this call : NOTE
9918                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9919                                                                                         player[i].stunned>0 ||
9920                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9921                                                                                 {
9922                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9923                                                                                         player[i].targetrotation=player[i].rotation;
9924                                                                                         player[i].forwardkeydown=0;
9925                                                                                         player[i].leftkeydown=0;
9926                                                                                         player[i].backkeydown=0;
9927                                                                                         player[i].rightkeydown=0;
9928                                                                                         player[i].jumpkeydown=0;
9929                                                                                         player[i].attackkeydown=0;
9930                                                                                         player[i].crouchkeydown=0;
9931                                                                                         player[i].throwkeydown=0;
9932                                                                                 }
9933
9934
9935                                                                                 facing=0;
9936                                                                                 facing.z=-1;
9937
9938                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9939                                                                                 facing=flatfacing;
9940
9941                                                                                 if(player[i].aitype==attacktypecutoff){
9942                                                                                         rotatetarget=player[0].coords-player[i].coords;
9943                                                                                         Normalise(&rotatetarget);
9944                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9945                                                                                         player[i].targetheadrotation*=360/6.28;
9946                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9947
9948                                                                                         player[i].targetheadrotation*=-1;
9949                                                                                         player[i].targetheadrotation+=180;
9950                                                                                         //player[i].targetheadrotation2=0;
9951                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9952                                                                                 }
9953                                                                                 else if(player[i].howactive>=typesleeping){
9954                                                                                         player[i].targetheadrotation=player[i].targetrotation;
9955                                                                                         player[i].targetheadrotation2=0;
9956                                                                                 }
9957                                                                                 else {
9958                                                                                         if(player[i].interestdelay<=0){
9959                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
9960                                                                                                 player[i].headtarget=player[i].coords;
9961                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
9962                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
9963                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
9964                                                                                                 player[i].headtarget+=player[i].facing*1.5;
9965                                                                                         }
9966                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
9967                                                                                         Normalise(&rotatetarget);
9968                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9969                                                                                         player[i].targetheadrotation*=360/6.28;
9970                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9971
9972                                                                                         player[i].targetheadrotation*=-1;
9973                                                                                         player[i].targetheadrotation+=180;
9974                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9975                                                                                 }
9976                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
9977                                                                         }
9978                                                                         if(animation[player[i].targetanimation].attack==reversed){
9979                                                                                 //player[i].targetrotation=player[i].rotation;
9980                                                                                 player[i].forwardkeydown=0;
9981                                                                                 player[i].leftkeydown=0;
9982                                                                                 player[i].backkeydown=0;
9983                                                                                 player[i].rightkeydown=0;
9984                                                                                 player[i].jumpkeydown=0;
9985                                                                                 player[i].attackkeydown=0;
9986                                                                                 //player[i].crouchkeydown=0;
9987                                                                                 player[i].throwkeydown=0;
9988                                                                         }
9989
9990                                                                         if(indialogue!=-1){
9991                                                                                 player[i].forwardkeydown=0;
9992                                                                                 player[i].leftkeydown=0;
9993                                                                                 player[i].backkeydown=0;
9994                                                                                 player[i].rightkeydown=0;
9995                                                                                 player[i].jumpkeydown=0;
9996                                                                                 player[i].crouchkeydown=0;
9997                                                                                 player[i].drawkeydown=0;
9998                                                                                 player[i].throwkeydown=0;
9999                                                                         }
10000
10001                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
10002                                                                         if(player[i].collided>1)player[i].collided=1;
10003                                                                         player[i].collided-=multiplier*4;
10004                                                                         player[i].whichdirectiondelay-=multiplier;
10005                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
10006                                                                                 player[i].avoidcollided=-.3;
10007                                                                                 player[i].whichdirection=abs(Random()%2);
10008                                                                                 player[i].whichdirectiondelay=.4;
10009                                                                         }
10010                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
10011                                                                         player[i].avoidcollided-=multiplier/4;
10012                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
10013                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
10014                                                                         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;
10015
10016                                                                         if(!player[i].throwkeydown){
10017                                                                                 player[i].throwtogglekeydown=0;
10018                                                                         }
10019                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
10020                                                                                 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)){
10021                                                                                         for(j=0;j<weapons.numweapons;j++){
10022                                                                                                 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)
10023                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
10024                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
10025                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
10026                                                                                                                                 player[i].throwtogglekeydown=1;
10027                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10028                                                                                                                                 player[i].target=0;
10029                                                                                                                                 player[i].targetframe=0;
10030                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10031                                                                                                                                 Normalise(&rotatetarget);
10032                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10033                                                                                                                                 player[i].targetrotation*=360/6.28;
10034                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10035                                                                                                                                 player[i].hasvictim=0;
10036                                                                                                                         }
10037                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10038                                                                                                                                 player[i].throwtogglekeydown=1;
10039                                                                                                                                 player[i].hasvictim=0;
10040
10041                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
10042                                                                                                                                 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))
10043                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
10044                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
10045                                                                                                                                                         float gLoc[3];
10046                                                                                                                                                         float vel[3];
10047                                                                                                                                                         gLoc[0]=player[i].coords.x;
10048                                                                                                                                                         gLoc[1]=player[i].coords.y;
10049                                                                                                                                                         gLoc[2]=player[i].coords.z;
10050                                                                                                                                                         vel[0]=player[i].velocity.x;
10051                                                                                                                                                         vel[1]=player[i].velocity.y;
10052                                                                                                                                                         vel[2]=player[i].velocity.z;
10053                                                                                                                                                         if(weapons.type[j]!=staff){
10054                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10055                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10056                                                                                                                                                                 FSOUND_SetVolume(channels[knifedrawsound], 128);
10057                                                                                                                                                                 FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10058                                                                                                                                                         }
10059
10060                                                                                                                                                         player[i].weaponactive=0;
10061                                                                                                                                                         weapons.owner[j]=player[i].id;
10062                                                                                                                                                         if(player[i].num_weapons>0){
10063                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10064                                                                                                                                                         }
10065                                                                                                                                                         player[i].num_weapons++;
10066                                                                                                                                                         player[i].weaponids[0]=j;
10067                                                                                                                                                 }
10068                                                                                                                                         }
10069                                                                                                                                         //}
10070                                                                                                                         }
10071                                                                                                                 }
10072                                                                                                                 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){
10073                                                                                                                         if(!player[i].isFlip()){
10074                                                                                                                                 player[i].throwtogglekeydown=1;
10075                                                                                                                                 player[i].targetanimation=removeknifeanim;
10076                                                                                                                                 player[i].target=0;
10077                                                                                                                                 player[i].targetframe=0;
10078                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10079                                                                                                                                 Normalise(&rotatetarget);
10080                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10081                                                                                                                                 player[i].targetrotation*=360/6.28;
10082                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10083                                                                                                                         }
10084                                                                                                                         if(player[i].isFlip()){
10085                                                                                                                                 player[i].throwtogglekeydown=1;
10086                                                                                                                                 player[i].hasvictim=0;
10087
10088                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
10089                                                                                                                                         if(player[i].weaponactive==-1)
10090                                                                                                                                                 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))
10091                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
10092                                                                                                                                                                 float gLoc[3];
10093                                                                                                                                                                 float vel[3];
10094                                                                                                                                                                 gLoc[0]=player[i].coords.x;
10095                                                                                                                                                                 gLoc[1]=player[i].coords.y;
10096                                                                                                                                                                 gLoc[2]=player[i].coords.z;
10097                                                                                                                                                                 vel[0]=player[i].velocity.x;
10098                                                                                                                                                                 vel[1]=player[i].velocity.y;
10099                                                                                                                                                                 vel[2]=player[i].velocity.z;
10100                                                                                                                                                                 if(weapons.type[k]!=staff){
10101                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10102                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10103                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10104                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10105                                                                                                                                                                 }
10106
10107                                                                                                                                                                 player[i].weaponactive=0;
10108                                                                                                                                                                 weapons.owner[k]=player[i].id;
10109                                                                                                                                                                 if(player[i].num_weapons>0){
10110                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10111                                                                                                                                                                 }
10112                                                                                                                                                                 player[i].num_weapons++;
10113                                                                                                                                                                 player[i].weaponids[0]=k;
10114                                                                                                                                                         }
10115                                                                                                                                 }
10116                                                                                                                         }
10117                                                                                                                 }
10118                                                                                                         }
10119                                                                                         }
10120                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10121                                                                                                 if(numplayers>1)
10122                                                                                                         for(j=0;j<numplayers;j++){
10123                                                                                                                 if(player[i].weaponactive==-1)
10124                                                                                                                         if(j!=i)
10125                                                                                                                                 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)){
10126                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
10127                                                                                                                                                 player[i].throwtogglekeydown=1;
10128                                                                                                                                                 player[i].victim=&player[j];
10129                                                                                                                                                 player[i].hasvictim=1;
10130                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10131                                                                                                                                                 player[i].target=0;
10132                                                                                                                                                 player[i].targetframe=0;
10133                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10134                                                                                                                                                 Normalise(&rotatetarget);
10135                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10136                                                                                                                                                 player[i].targetrotation*=360/6.28;
10137                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10138                                                                                                                                         }
10139                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10140                                                                                                                                                 player[i].throwtogglekeydown=1;
10141                                                                                                                                                 player[i].victim=&player[j];
10142                                                                                                                                                 player[i].hasvictim=1;
10143                                                                                                                                                 int k = player[j].weaponids[0];
10144                                                                                                                                                 if(player[i].hasvictim){
10145                                                                                                                                                         float gLoc[3];
10146                                                                                                                                                         float vel[3];
10147                                                                                                                                                         gLoc[0]=player[i].coords.x;
10148                                                                                                                                                         gLoc[1]=player[i].coords.y;
10149                                                                                                                                                         gLoc[2]=player[i].coords.z;
10150                                                                                                                                                         vel[0]=player[i].velocity.x;
10151                                                                                                                                                         vel[1]=player[i].velocity.y;
10152                                                                                                                                                         vel[2]=player[i].velocity.z;
10153                                                                                                                                                         bool fleshstuck;
10154                                                                                                                                                         fleshstuck=0;
10155                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
10156                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10157                                                                                                                                                                         fleshstuck=1;
10158                                                                                                                                                                 }
10159                                                                                                                                                         }
10160                                                                                                                                                         if(!fleshstuck){
10161                                                                                                                                                                 if(weapons.type[k]!=staff){
10162                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10163                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10164                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10165                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10166                                                                                                                                                                 }
10167                                                                                                                                                         }
10168                                                                                                                                                         if(fleshstuck){
10169                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, TRUE);
10170                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
10171                                                                                                                                                                 FSOUND_SetVolume(channels[fleshstabremovesound], 128);
10172                                                                                                                                                                 FSOUND_SetPaused(channels[fleshstabremovesound], FALSE);
10173                                                                                                                                                         }
10174
10175                                                                                                                                                         player[i].weaponactive=0;
10176                                                                                                                                                         if(weapons.owner[k]!=-1){
10177                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
10178                                                                                                                                                                 else player[i].victim->num_weapons=1;
10179
10180                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
10181                                                                                                                                                                 player[i].victim->skeleton.free=1;
10182                                                                                                                                                                 player[i].victim->skeleton.broken=0;
10183
10184                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
10185                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
10186                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
10187                                                                                                                                                                 }
10188
10189                                                                                                                                                                 XYZ relative;
10190                                                                                                                                                                 relative=0;
10191                                                                                                                                                                 relative.y=10;
10192                                                                                                                                                                 Normalise(&relative);
10193                                                                                                                                                                 XYZ footvel,footpoint;
10194                                                                                                                                                                 footvel=0;
10195                                                                                                                                                                 footpoint=weapons.position[k];
10196                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
10197                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10198                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
10199                                                                                                                                                                                 weapons.bloody[k]=2;
10200                                                                                                                                                                                 weapons.blooddrip[k]=5;
10201                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
10202                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
10203                                                                                                                                                                                 player[i].victim->DoDamage(2000);
10204                                                                                                                                                                         }
10205                                                                                                                                                                 }
10206                                                                                                                                                                 if(player[i].victim->num_weapons>0){
10207                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
10208                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
10209                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
10210                                                                                                                                                                 }
10211
10212                                                                                                                                                                 player[i].victim->weaponactive=-1;
10213
10214                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
10215                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
10216                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
10217                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
10218                                                                                                                                                         }
10219                                                                                                                                                         weapons.owner[k]=i;
10220                                                                                                                                                         if(player[i].num_weapons>0){
10221                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10222                                                                                                                                                         }
10223                                                                                                                                                         player[i].num_weapons++;
10224                                                                                                                                                         player[i].weaponids[0]=k;
10225                                                                                                                                                 }
10226                                                                                                                                         }
10227                                                                                                                                 }
10228                                                                                                         }
10229                                                                                         }
10230                                                                                 }
10231                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10232                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
10233                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
10234                                                                                                         if(numplayers>1)
10235                                                                                                                 for(j=0;j<numplayers;j++){
10236                                                                                                                         if(i!=j)
10237                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
10238                                                                                                                                         if(hostile)
10239                                                                                                                                                 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)){
10240                                                                                                                                                         if(!player[i].isFlip()){
10241                                                                                                                                                                 player[i].throwtogglekeydown=1;
10242                                                                                                                                                                 player[i].victim=&player[j];
10243                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10244                                                                                                                                                                 player[i].target=0;
10245                                                                                                                                                                 player[i].targetframe=0;
10246                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10247                                                                                                                                                                 Normalise(&rotatetarget);
10248                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10249                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10250                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10251
10252                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10253                                                                                                                                                         }
10254                                                                                                                                                         if(player[i].isFlip()){
10255                                                                                                                                                                 if(player[i].weaponactive!=-1){
10256                                                                                                                                                                         player[i].throwtogglekeydown=1;
10257                                                                                                                                                                         player[i].victim=&player[j];
10258                                                                                                                                                                         XYZ aim;
10259                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10260                                                                                                                                                                         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);                                                
10261                                                                                                                                                                         Normalise(&aim);
10262
10263                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10264
10265                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10266                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10267                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10268                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10269                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10270                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10271                                                                                                                                                                         player[i].num_weapons--;
10272                                                                                                                                                                         if(player[i].num_weapons){
10273                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10274                                                                                                                                                                         }
10275                                                                                                                                                                         player[i].weaponactive=-1;
10276                                                                                                                                                                 }               
10277                                                                                                                                                         }
10278                                                                                                                                                 }
10279                                                                                                                 }
10280                                                                                         }
10281                                                                                 }
10282                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10283                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10284                                                                                         {
10285                                                                                                 player[i].throwtogglekeydown=1;
10286                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10287                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10288                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10289                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10290                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10291                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10292                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10293                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10294                                                                                                 player[i].num_weapons--;
10295                                                                                                 if(player[i].num_weapons){
10296                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10297                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10298                                                                                                 }
10299
10300                                                                                                 player[i].weaponactive=-1;
10301                                                                                                 for(j=0;j<numplayers;j++){
10302                                                                                                         player[j].wentforweapon=0;
10303                                                                                                 }
10304                                                                                         }
10305                                                                                 }
10306
10307                                                                         }
10308
10309                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10310                                                                                 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)){
10311                                                                                         //Setenvironment(1-environment);
10312                                                                                         bool isgood;
10313                                                                                         isgood=1;
10314                                                                                         if(player[i].weaponactive!=-1){
10315                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10316                                                                                         }
10317                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10318                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10319                                                                                                         player[i].targetanimation=drawrightanim;
10320                                                                                                         player[i].targetframe=0;
10321                                                                                                         player[i].target=0;
10322                                                                                                         player[i].drawtogglekeydown=1;
10323                                                                                                 }
10324                                                                                                 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){
10325                                                                                                         player[i].targetanimation=drawleftanim;
10326                                                                                                         player[i].targetframe=0;
10327                                                                                                         player[i].target=0;
10328                                                                                                         player[i].drawtogglekeydown=1;
10329                                                                                                 }
10330                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10331                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10332                                                                                                         player[i].targetframe=0;
10333                                                                                                         player[i].target=0;
10334                                                                                                         player[i].drawtogglekeydown=1;
10335                                                                                                 }
10336                                                                                         }                        
10337                                                                                 }
10338                                                                                 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){
10339                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10340                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10341                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10342                                                                                                 player[i].targetframe=0;
10343                                                                                                 player[i].target=0;
10344                                                                                                 player[i].hasvictim=0;
10345                                                                                                 //player[i].attacktogglekeydown=1;
10346                                                                                         }
10347                                                                                 }
10348
10349                                                                                 if(!player[i].drawkeydown){
10350                                                                                         player[i].drawtogglekeydown=0;
10351                                                                                 }
10352
10353                                                                                 if(i==0){
10354                                                                                         absflatfacing=0;
10355                                                                                         absflatfacing.z=-1;
10356
10357                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10358                                                                                 }
10359                                                                                 else absflatfacing=flatfacing;
10360
10361                                                                                 if(indialogue!=-1){
10362                                                                                         player[i].forwardkeydown=0;
10363                                                                                         player[i].leftkeydown=0;
10364                                                                                         player[i].backkeydown=0;
10365                                                                                         player[i].rightkeydown=0;
10366                                                                                         player[i].jumpkeydown=0;
10367                                                                                         player[i].crouchkeydown=0;
10368                                                                                         player[i].drawkeydown=0;
10369                                                                                         player[i].throwkeydown=0;
10370                                                                                 }
10371                                                                                 movekey=0;
10372                                                                                 //Do controls
10373                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10374                                                                                         if(!player[i].forwardkeydown){
10375                                                                                                 player[i].forwardstogglekeydown=0;
10376                                                                                         }
10377                                                                                         if(player[i].crouchkeydown){
10378                                                                                                 //Crouch
10379                                                                                                 target=-2;
10380                                                                                                 if(i==0){
10381                                                                                                         player[i].superruntoggle=1;
10382                                                                                                         if(numplayers>1)
10383                                                                                                                 for(j=0;j<numplayers;j++){
10384                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10385                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10386                                                                                                                                         player[i].superruntoggle=0;
10387                                                                                                                                 }
10388                                                                                                                         }
10389                                                                                                                 }
10390                                                                                                 }
10391
10392                                                                                                 if(numplayers>1)
10393                                                                                                         for(j=0;j<numplayers;j++){
10394                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10395                                                                                                                         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))){
10396                                                                                                                                 if(target>=0)target=-1;
10397                                                                                                                                 else target=j;
10398                                                                                                                         }
10399                                                                                                                 }
10400                                                                                                         }
10401                                                                                                         if(target>=0)player[target].Reverse();
10402                                                                                                         player[i].lowreversaldelay=.5;
10403
10404                                                                                                         if(player[i].isIdle()){
10405                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10406                                                                                                                 player[i].target=0;
10407                                                                                                                 player[i].targetframe=0;
10408                                                                                                                 player[i].transspeed=10;
10409                                                                                                         }
10410                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10411                                                                                                                 player[i].targetanimation=rollanim;
10412                                                                                                                 player[i].target=0;
10413                                                                                                                 player[i].targetframe=0;
10414                                                                                                                 player[i].transspeed=20;
10415                                                                                                         }
10416                                                                                         }
10417                                                                                         if(!player[i].crouchkeydown){
10418                                                                                                 //Uncrouch
10419                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10420                                                                                                 target=-2;
10421                                                                                                 if(player[i].isCrouch()){
10422                                                                                                         if(numplayers>1)
10423                                                                                                                 for(j=0;j<numplayers;j++){
10424                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10425                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10426                                                                                                                                         if(target>=0)target=-1;
10427                                                                                                                                         else target=j;
10428                                                                                                                                 }
10429                                                                                                                         }
10430                                                                                                                 }
10431                                                                                                                 if(target>=0)player[target].Reverse();
10432                                                                                                                 player[i].highreversaldelay=.5;
10433
10434                                                                                                                 if(player[i].isCrouch()){                                               
10435                                                                                                                         if(!player[i].wasCrouch()){
10436                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10437                                                                                                                                 player[i].currentframe=0;
10438                                                                                                                         }
10439                                                                                                                         player[i].target=0;
10440                                                                                                                         player[i].targetanimation=player[i].getIdle();
10441                                                                                                                         player[i].targetframe=0;
10442                                                                                                                         player[i].transspeed=10;
10443                                                                                                                 }
10444                                                                                                 }
10445                                                                                                 if(player[i].targetanimation==sneakanim){
10446                                                                                                         player[i].targetanimation=player[i].getIdle();
10447                                                                                                         player[i].target=0;
10448                                                                                                         player[i].targetframe=0;
10449                                                                                                         player[i].transspeed=10;
10450                                                                                                 }
10451                                                                                         }
10452                                                                                         if(player[i].forwardkeydown){
10453                                                                                                 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)){
10454                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10455                                                                                                         else player[i].targetanimation=player[i].getRun();
10456                                                                                                         player[i].target=0;
10457                                                                                                         player[i].targetframe=0;
10458                                                                                                 }
10459                                                                                                 if(player[i].isCrouch()){
10460                                                                                                         player[i].targetanimation=sneakanim;
10461                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10462                                                                                                         player[i].targetframe=0;
10463                                                                                                 }
10464                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10465                                                                                                         player[i].targetanimation=climbanim;
10466                                                                                                         player[i].target=0;
10467                                                                                                         player[i].targetframe=1;
10468                                                                                                         player[i].jumpclimb=1;
10469                                                                                                 }
10470                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10471                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10472                                                                                                 }
10473                                                                                                 player[i].forwardstogglekeydown=1;
10474                                                                                                 movekey=1;
10475                                                                                         }
10476                                                                                         if (player[i].rightkeydown){
10477                                                                                                 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)){
10478                                                                                                         player[i].targetanimation=player[i].getRun();
10479                                                                                                         player[i].target=0;
10480                                                                                                         player[i].targetframe=0;
10481                                                                                                 }
10482                                                                                                 if(player[i].isCrouch()){
10483                                                                                                         player[i].targetanimation=sneakanim;
10484                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10485                                                                                                         player[i].targetframe=0;
10486                                                                                                 }
10487                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10488                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10489                                                                                                 }
10490                                                                                                 player[i].targetrotation-=90;
10491                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10492                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10493                                                                                                 movekey=1;
10494                                                                                         }
10495                                                                                         if ( player[i].leftkeydown){
10496                                                                                                 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)){
10497                                                                                                         player[i].targetanimation=player[i].getRun();
10498                                                                                                         player[i].target=0;
10499                                                                                                         player[i].targetframe=0;
10500                                                                                                 }
10501                                                                                                 if(player[i].isCrouch()){
10502                                                                                                         player[i].targetanimation=sneakanim;
10503                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10504                                                                                                         player[i].targetframe=0;
10505                                                                                                 }
10506                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10507                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10508                                                                                                 }
10509                                                                                                 player[i].targetrotation+=90;
10510                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10511                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10512                                                                                                 movekey=1;
10513                                                                                         }
10514                                                                                         if(player[i].backkeydown){
10515                                                                                                 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)){
10516                                                                                                         player[i].targetanimation=player[i].getRun();
10517                                                                                                         player[i].target=0;
10518                                                                                                         player[i].targetframe=0;
10519                                                                                                 }
10520                                                                                                 if(player[i].isCrouch()){
10521                                                                                                         player[i].targetanimation=sneakanim;
10522                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10523                                                                                                         player[i].targetframe=0;
10524                                                                                                 }
10525                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10526                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10527                                                                                                 }
10528                                                                                                 if(player[i].targetanimation==hanganim){
10529                                                                                                         player[i].currentanimation=jumpdownanim;
10530                                                                                                         player[i].targetanimation=jumpdownanim;
10531                                                                                                         player[i].target=0;
10532                                                                                                         player[i].currentframe=0;
10533                                                                                                         player[i].targetframe=1;
10534                                                                                                         player[i].velocity=0;
10535                                                                                                         player[i].velocity.y+=gravity;
10536                                                                                                         player[i].coords.y-=1.4;
10537                                                                                                         player[i].grabdelay=1;
10538                                                                                                 }
10539                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10540                                                                                                         player[i].targetrotation+=180;
10541                                                                                                 movekey=1;
10542                                                                                         }
10543                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10544                                                                                                 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)){
10545                                                                                                         player[i].jumpstart=0;
10546                                                                                                         player[i].targetanimation=jumpupanim;
10547                                                                                                         player[i].target=0;
10548                                                                                                         player[i].targetframe=0;
10549                                                                                                         player[i].rotation=player[i].targetrotation;
10550                                                                                                         player[i].transspeed=20;
10551                                                                                                         player[i].FootLand(0,1);
10552                                                                                                         player[i].FootLand(1,1);
10553
10554                                                                                                         facing=0;
10555                                                                                                         facing.z=-1;
10556                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10557
10558                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10559                                                                                                         if(!movekey)player[i].velocity=0;
10560
10561                                                                                                         //Dodge sweep?
10562                                                                                                         target=-2;
10563                                                                                                         if(numplayers>1)
10564                                                                                                                 for(j=0;j<numplayers;j++){
10565                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10566                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10567                                                                                                                                         if(target>=0)target=-1;
10568                                                                                                                                         else target=j;
10569                                                                                                                                 }
10570                                                                                                                         }
10571                                                                                                                 }
10572                                                                                                                 if(target>=0)player[i].velocity.y=1;
10573                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10574                                                                                                                         player[i].velocity.y=7;
10575                                                                                                                         player[i].crouchtogglekeydown=1;
10576                                                                                                                 }
10577                                                                                                                 else player[i].velocity.y=5;
10578
10579                                                                                                                 if(mousejump&&i==0&&debugmode){
10580                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10581                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10582                                                                                                                 }
10583
10584                                                                                                                 player[i].coords.y+=.2;
10585                                                                                                                 player[i].jumppower-=1;
10586
10587                                                                                                                 static float gLoc[3];
10588                                                                                                                 static float vel[3];
10589                                                                                                                 gLoc[0]=player[i].coords.x;
10590                                                                                                                 gLoc[1]=player[i].coords.y;
10591                                                                                                                 gLoc[2]=player[i].coords.z;
10592                                                                                                                 vel[0]=player[i].velocity.x;
10593                                                                                                                 vel[1]=player[i].velocity.y;
10594                                                                                                                 vel[2]=player[i].velocity.z;
10595
10596                                                                                                                 if(i==0){
10597                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
10598                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10599                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
10600                                                                                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
10601                                                                                                                 }
10602
10603                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
10604                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10605                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
10606                                                                                                                 FSOUND_SetPaused(channels[jumpsound], FALSE);
10607                                                                                                 }               
10608                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10609                                                                                                         player[i].targetanimation=player[i].getLanding();
10610                                                                                                         player[i].landhard=0;
10611                                                                                                         player[i].target=0;
10612                                                                                                         player[i].targetframe=2;
10613                                                                                                         player[i].jumpstart=1;
10614                                                                                                         player[i].tempdeltav=deltav;
10615                                                                                                 }               
10616                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10617                                                                                                         if(player[i].jumppower>multiplier*6){
10618                                                                                                                 player[i].velocity.y+=multiplier*6;
10619                                                                                                                 player[i].jumppower-=multiplier*6;
10620                                                                                                         }
10621                                                                                                         if(player[i].jumppower<=multiplier*6){
10622                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10623                                                                                                                 player[i].jumppower=0;
10624                                                                                                         }
10625                                                                                                 }
10626                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;           
10627                                                                                         }
10628
10629                                                                                         if(!movekey){
10630                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10631                                                                                                         player[i].targetanimation=player[i].getStop();
10632                                                                                                         player[i].target=0;
10633                                                                                                         player[i].targetframe=0;
10634                                                                                                 }
10635                                                                                                 if(player[i].targetanimation==sneakanim){
10636                                                                                                         player[i].targetanimation=player[i].getCrouch();
10637                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10638                                                                                                         player[i].targetframe=0;
10639                                                                                                 }
10640                                                                                         }
10641                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10642                                                                                                 player[i].targetanimation=player[i].getStop();
10643                                                                                                 player[i].target=0;
10644                                                                                                 player[i].targetframe=0;
10645                                                                                         }
10646                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10647                                                                                                 player[i].targetanimation=player[i].getStop();
10648                                                                                                 player[i].target=0;
10649                                                                                                 player[i].targetframe=0;
10650                                                                                         }
10651                                                                                 }
10652                                                                 }
10653                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10654                                                         }
10655
10656                                                         //Rotation
10657                                                         for(k=0;k<numplayers;k++){
10658                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10659                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10660                                                                         else player[k].rotation+=360;
10661                                                                 }
10662
10663                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10664                                                                         player[k].targetanimation=player[k].getStop();
10665                                                                         player[k].targetframe=0;
10666                                                                         player[k].target=0;
10667                                                                 }
10668
10669                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10670                                                                         player[k].targettilt=0;
10671                                                                 }
10672                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10673                                                                         player[k].targettilt=0;
10674                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10675                                                                         player[k].jumppower+=multiplier*7;
10676                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10677                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10678                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10679                                                                 }
10680
10681                                                                 if(player[k].isRun()){
10682                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10683                                                                 }
10684
10685                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10686                                                                 else if(player[k].tilt>player[k].targettilt){
10687                                                                         player[k].tilt-=multiplier*150;
10688                                                                 }
10689                                                                 else if(player[k].tilt<player[k].targettilt){
10690                                                                         player[k].tilt+=multiplier*150;
10691                                                                 }
10692
10693                                                                 player[k].grabdelay-=multiplier;
10694                                                         }
10695
10696                                                         for(k=0;k<numplayers;k++){
10697                                                                 player[k].DoAnimations();
10698                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10699                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10700                                                         }
10701
10702                                                         objects.DoStuff();
10703                                                         /*
10704                                                         player[0].righthandmorphstart=0;
10705                                                         player[0].righthandmorphend=1;
10706                                                         player[0].lefthandmorphstart=0;
10707                                                         player[0].lefthandmorphend=1;
10708                                                         player[0].headmorphstart=0;
10709                                                         player[0].headmorphend=2;*/
10710
10711                                                         /*
10712                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10713                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10714                                                         player[0].righthandmorphend=1;
10715                                                         player[0].targetrighthandmorphness=1;
10716
10717                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10718                                                         player[0].lefthandmorphend=0;
10719                                                         player[0].targetlefthandmorphness=1;
10720
10721                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10722                                                         player[0].headmorphend=2;
10723                                                         player[0].targetheadmorphness=1;
10724                                                         }
10725                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10726                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10727                                                         player[0].righthandmorphend=0;
10728                                                         player[0].targetrighthandmorphness=1;
10729
10730                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10731                                                         player[0].lefthandmorphend=1;
10732                                                         player[0].targetlefthandmorphness=1;
10733
10734                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10735                                                         player[0].headmorphend=0;
10736                                                         player[0].targetheadmorphness=1;
10737                                                         }
10738                                                         */
10739                                                         if(numenvsounds!=0)
10740                                                                 for(j=numenvsounds-1;j>=0;j--){
10741                                                                         envsoundlife[j]-=multiplier;
10742                                                                         if(envsoundlife[j]<0){
10743                                                                                 numenvsounds--;
10744                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10745                                                                                 envsound[j]=envsound[numenvsounds];
10746                                                                         }
10747                                                                 }
10748                                                                 if(!slomo)FSOUND_SetFrequency(FSOUND_ALL, 22050);
10749                                                                 if(slomo)FSOUND_SetFrequency(FSOUND_ALL, slomofreq);
10750
10751                                                                 if(tutoriallevel==1){
10752                                                                         XYZ temp;
10753                                                                         XYZ temp2;
10754                                                                         XYZ temp3;
10755                                                                         XYZ oldtemp;
10756                                                                         XYZ oldtemp2;
10757                                                                         temp.x=1011;
10758                                                                         temp.y=84;
10759                                                                         temp.z=491;
10760                                                                         temp2.x=1025;
10761                                                                         temp2.y=75;
10762                                                                         temp2.z=447;
10763                                                                         temp3.x=1038;
10764                                                                         temp3.y=76;
10765                                                                         temp3.z=453;
10766                                                                         oldtemp=temp;
10767                                                                         oldtemp2=temp2;
10768                                                                         if(tutorialstage>=51)
10769                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10770                                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
10771
10772                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10773                                                                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10774                                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
10775
10776                                                                                         gameon=0;
10777                                                                                         mainmenu=5;
10778
10779                                                                                         float gLoc[3]={0,0,0};
10780                                                                                         float vel[3]={0,0,0};
10781                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10782                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10783                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10784                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10785                                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10786                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10787
10788                                                                                         flashr=1;
10789                                                                                         flashg=0;
10790                                                                                         flashb=0;
10791                                                                                         flashamount=1;
10792                                                                                         flashdelay=1;
10793                                                                                 }
10794                                                                                 if(tutorialstage<51)
10795                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10796                                                                                                 float gLoc[3];
10797                                                                                                 float vel[3];
10798                                                                                                 gLoc[0]=player[0].coords.x;
10799                                                                                                 gLoc[1]=player[0].coords.y;
10800                                                                                                 gLoc[2]=player[0].coords.z;
10801                                                                                                 vel[0]=0;
10802                                                                                                 vel[1]=0;
10803                                                                                                 vel[2]=0;
10804                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10805                                                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10806                                                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
10807                                                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
10808
10809                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10810
10811                                                                                                 flashr=1;
10812                                                                                                 flashg=1;
10813                                                                                                 flashb=1;
10814                                                                                                 flashamount=1;
10815                                                                                                 flashdelay=1;
10816                                                                                         }
10817                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10818                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10819                                                                                                         float gLoc[3];
10820                                                                                                         float vel[3];
10821                                                                                                         gLoc[0]=player[1].coords.x;
10822                                                                                                         gLoc[1]=player[1].coords.y;
10823                                                                                                         gLoc[2]=player[1].coords.z;
10824                                                                                                         vel[0]=0;
10825                                                                                                         vel[1]=0;
10826                                                                                                         vel[2]=0;
10827                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10828                                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10829                                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10830                                                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10831
10832                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10833                                                                                                                 if(Random()%2==0){
10834                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10835                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10836                                                                                                                         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;
10837                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10838                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10839                                                                                                                 }
10840                                                                                                         }
10841
10842                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10843                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10844                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10845                                                                                                                 if(Random()%2==0){
10846                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10847                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10848                                                                                                                         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;
10849                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10850                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10851                                                                                                                 }
10852                                                                                                         }
10853                                                                                                 }
10854                                                                 }
10855
10856
10857                                                                 //3d sound
10858                                                                 static float gLoc[3];
10859                                                                 gLoc[0]=viewer.x;
10860                                                                 gLoc[1]=viewer.y;
10861                                                                 gLoc[2]=viewer.z;
10862                                                                 static float vel[3];
10863                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10864                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10865                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10866
10867                                                                 //Set orientation with forward and up vectors
10868                                                                 static XYZ upvector;
10869                                                                 upvector=0;
10870                                                                 upvector.z=-1;
10871
10872                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10873                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10874
10875                                                                 facing=0;
10876                                                                 facing.z=-1;
10877                                                                 
10878                                                                 facing=DoRotation(facing,-rotation2,0,0);
10879                                                                 facing=DoRotation(facing,0,0-rotation,0);
10880                 
10881                 
10882                                                                 static float ori[6];
10883                                                                 ori[0] = -facing.x;
10884                                                                 ori[1] = facing.y;
10885                                                                 ori[2] = -facing.z;
10886                                                                 ori[3] = -upvector.x;
10887                                                                 ori[4] = upvector.y;
10888                                                                 ori[5] = -upvector.z;
10889
10890                                                                 FSOUND_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10891                                                                 FSOUND_Update();
10892
10893                                                                 oldviewer=viewer;
10894                 }
10895         }
10896
10897         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10898                 Screenshot();
10899                 freezetogglekeydown=1;
10900         }
10901 }
10902
10903 void    Game::TickOnce(){
10904         //if(!console){
10905         if(!mainmenu)
10906                 if(directing||indialogue==-1){
10907                         rotation+=deltah*.7;
10908                         if(!invertmouse)rotation2+=deltav*.7;
10909                         if(invertmouse)rotation2-=deltav*.7;
10910                         if(rotation2>90)rotation2=90;
10911                         if(rotation2<-70)rotation2=-70;
10912                 }
10913                 if(mainmenu)rotation+=multiplier*5;
10914                 if(!mainmenu&&!indemo&&!registered){
10915                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
10916                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10917                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10918                         FSOUND_SetVolume(channels[stream_music3], 256);
10919
10920                         gameon=0;
10921                         mainmenu=12;
10922
10923                         float gLoc[3]={0,0,0};
10924                         float vel[3]={0,0,0};
10925                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10926                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10927                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10928                         FSOUND_SetVolume(channels[fireendsound], 256);
10929                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10930                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10931
10932                         flashr=1;
10933                         flashg=0;
10934                         flashb=0;
10935                         flashamount=1;
10936                         flashdelay=1;
10937                 }
10938
10939                 if(tryquit==1&&!registered&&mainmenu!=12){
10940                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
10941                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10942                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10943                         FSOUND_SetVolume(channels[stream_music3], 256);
10944
10945                         gameon=0;
10946                         mainmenu=12;
10947
10948                         float gLoc[3]={0,0,0};
10949                         float vel[3]={0,0,0};
10950                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10951                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10952                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10953                         FSOUND_SetVolume(channels[fireendsound], 256);
10954                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10955                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10956
10957                         flashr=1;
10958                         flashg=0;
10959                         flashb=0;
10960                         flashamount=1;
10961                         flashdelay=1;
10962                 }
10963                 //}
10964 }
10965
10966 void    Game::TickOnceAfter(){
10967         static XYZ colviewer;
10968         static XYZ coltarget;
10969         static XYZ target;
10970         static XYZ col;
10971         static float brotate;
10972         static XYZ facing;
10973         static int i,j;
10974         static float changedelay;
10975         static bool alldead;
10976         static float unseendelay;
10977         static float cameraspeed;
10978
10979         if(!mainmenu){
10980
10981                 if(environment==snowyenvironment)music1=stream_music1snow;
10982                 if(environment==grassyenvironment)music1=stream_music1grass;
10983                 if(environment==desertenvironment)music1=stream_music1desert;
10984
10985                 realthreat=0;
10986
10987                 musictype=music1;
10988                 for(i=0;i<numplayers;i++){
10989                         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)){
10990                                 musictype=stream_music2;
10991                                 realthreat=1;
10992                         }
10993                 }
10994                 if(player[0].dead)musictype=stream_music3;
10995
10996
10997                 if(musictype==stream_music2){
10998                         unseendelay=1;
10999                 }
11000
11001                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
11002                         unseendelay-=multiplier;
11003                         if(unseendelay>0){
11004                                 musictype=stream_music2;
11005                         }
11006                 }
11007
11008
11009                 if(loading==2){
11010                         musictype=stream_music3;
11011                         musicvolume[2]=512;
11012                         musicvolume[0]=0;
11013                         musicvolume[1]=0;
11014                         musicvolume[3]=0;
11015                 }       
11016
11017                 if(musictoggle){                        
11018                         if(musictype!=oldmusictype&&musictype==stream_music2){
11019                                 static float gLoc[3];
11020                                 static float vel[3];
11021                                 gLoc[0]=cameraloc.x;
11022                                 gLoc[1]=cameraloc.y;
11023                                 gLoc[2]=cameraloc.z;
11024                                 vel[0]=0;
11025                                 vel[1]=0;
11026                                 vel[2]=0;
11027                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, TRUE);
11028                                 FSOUND_SetVolume(channels[alarmsound], 512);
11029                                 FSOUND_SetPaused(channels[alarmsound], FALSE);
11030
11031                         }
11032                 }
11033                 musicselected=musictype;
11034
11035                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
11036                 else musicvolume[0]-=multiplier*450;
11037                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
11038                 else musicvolume[1]-=multiplier*450;
11039                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
11040                 else musicvolume[2]-=multiplier*450;
11041                 /*
11042                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
11043                 else musicvolume[0]-=multiplier*450;
11044                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
11045                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
11046                 else musicvolume[1]-=multiplier*100;
11047                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
11048                 else musicvolume[2]-=multiplier*450;*/
11049
11050                 for(i=0;i<3;i++){
11051                         if(musicvolume[i]<0)musicvolume[i]=0;
11052                         if(musicvolume[i]>512)musicvolume[i]=512;
11053                 }
11054
11055                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
11056
11057                 if(musictoggle){                
11058                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
11059                                 PlayStreamEx( music1, strm[music1], NULL, TRUE);
11060                                 FSOUND_SetPaused(channels[music1], FALSE);
11061                         }
11062                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
11063                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, TRUE);
11064                                 FSOUND_SetPaused(channels[stream_music2], FALSE);
11065                         }
11066                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
11067                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11068                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
11069                         }
11070                 }
11071
11072                 if(!musictoggle){               
11073                         FSOUND_SetPaused(channels[music1], TRUE);
11074                         FSOUND_SetPaused(channels[stream_music2], TRUE);
11075                         FSOUND_SetPaused(channels[stream_music3], TRUE);
11076
11077                         for(i=0;i<4;i++){
11078                                 oldmusicvolume[i]=0;
11079                                 musicvolume[i]=0;
11080                         }
11081                 }
11082
11083                 if(musictoggle){                
11084                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
11085                                 FSOUND_SetPaused(channels[music1], TRUE);
11086                         }
11087                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
11088                                 FSOUND_SetPaused(channels[stream_music2], TRUE);
11089                         }
11090                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
11091                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
11092                         }
11093
11094                         if(musicvolume[0]!=oldmusicvolume[0]){
11095                                 FSOUND_SetVolume(channels[music1], musicvolume[0]);
11096                         }
11097                         if(musicvolume[1]!=oldmusicvolume[1]){
11098                                 FSOUND_SetVolume(channels[stream_music2], musicvolume[1]);
11099                         }
11100                         if(musicvolume[2]!=oldmusicvolume[2]){
11101                                 FSOUND_SetVolume(channels[stream_music3], musicvolume[2]);
11102                         }
11103
11104                         for(i=0;i<3;i++){
11105                                 oldmusicvolume[i]=musicvolume[i];
11106                         }
11107                 }
11108
11109                 killhotspot=2;
11110                 if(numhotspots)
11111                         for(i=0;i<numhotspots;i++){
11112                                 if(hotspottype[i]>10&&hotspottype[i]<20){
11113                                         if(player[hotspottype[i]-10].dead==0){
11114                                                 killhotspot=0;
11115                                         }
11116                                         else if(killhotspot==2)
11117                                                 killhotspot=1;
11118                                 }
11119                         }
11120                         if(killhotspot==2)killhotspot=0;
11121
11122
11123                         winhotspot=0;
11124                         if(numhotspots)
11125                                 for(i=0;i<numhotspots;i++){
11126                                         if(hotspottype[i]==-1){
11127                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
11128                                                         winhotspot=1;
11129                                         }
11130                                 }
11131
11132                                 int numalarmed=0;
11133                                 if(numplayers>1)
11134                                         for(i=1;i<numplayers;i++){              
11135                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
11136                                         }
11137                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
11138
11139                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){          
11140                                                 if(player[0].dead&&changedelay<=0){
11141                                                         changedelay=1;
11142                                                         targetlevel=whichlevel;
11143                                                 }
11144                                                 alldead=1;
11145                                                 if(numplayers>1)
11146                                                         for(i=1;i<numplayers;i++){              
11147                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
11148                                                         }
11149
11150
11151                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
11152                                                                 changedelay=1;
11153                                                                 targetlevel=whichlevel+1;
11154                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11155                                                         }
11156                                                         if(winhotspot||windialogue){
11157                                                                 changedelay=0.1;
11158                                                                 targetlevel=whichlevel+1;
11159                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11160                                                         }
11161
11162
11163                                                         if(killhotspot){
11164                                                                 changedelay=1;
11165                                                                 targetlevel=whichlevel+1;
11166                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11167                                                         }
11168
11169                                                         if(changedelay>0&&!player[0].dead&&!won){
11170                                                                 //high scores, awards, win
11171                                                                 if(campaign){
11172                                                                         won=1;
11173                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11174                                                                         accountcampaignchoicesmade[accountactive]++;
11175                                                                         accountcampaignscore[accountactive]+=bonustotal;
11176                                                                         scoreadded=1;
11177                                                                         accountcampaigntime[accountactive]+=leveltime;
11178                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
11179
11180                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11181                                                                 }
11182                                                                 else
11183                                                                 {
11184                                                                         won=1;
11185                                                                         if(!debugmode){
11186                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
11187                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;            
11188                                                                         }
11189                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11190
11191                                                                 }
11192                                                         }
11193                                         }
11194
11195                                         if(!winfreeze){
11196
11197                                                 if(leveltime<1){
11198                                                         loading=0;
11199                                                         changedelay=.1;
11200                                                         alldead=0;
11201                                                         winhotspot=0;
11202                                                         killhotspot=0;
11203                                                 }
11204
11205                                                 if(!editorenabled&&gameon&&!mainmenu){
11206                                                         if(changedelay!=-999)changedelay-=multiplier/7;
11207                                                         if(player[0].dead)targetlevel=whichlevel;
11208                                                         if(loading==2&&!campaign){
11209                                                                 flashr=1;
11210                                                                 flashg=0;
11211                                                                 flashb=0;
11212                                                                 flashamount=1;
11213                                                                 flashdelay=1;
11214                                                                 loadtime=0;
11215
11216                                                                 float gLoc[3]={0,0,0};
11217                                                                 float vel[3]={0,0,0};
11218                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11219                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11220                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11221                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11222                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
11223                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11224
11225                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
11226                                                                         startbonustotal=bonustotal;
11227                                                                 }
11228                                                                 if(!player[0].dead)Loadlevel(targetlevel);
11229                                                                 if(player[0].dead)Loadlevel(whichlevel);
11230
11231                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11232                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11233                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11234                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11235                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
11236                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11237
11238                                                                 loading=3;
11239                                                         }
11240                                                         if(loading==2&&targetlevel==whichlevel){
11241                                                                 flashr=1;
11242                                                                 flashg=0;
11243                                                                 flashb=0;
11244                                                                 flashamount=1;
11245                                                                 flashdelay=1;
11246                                                                 loadtime=0;
11247
11248                                                                 float gLoc[3]={0,0,0};
11249                                                                 float vel[3]={0,0,0};
11250                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11251                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11252                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11253                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11254                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
11255                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11256
11257                                                                 for(i=0;i<255;i++){
11258                                                                         mapname[i]='\0';
11259                                                                 }
11260                                                                 mapname[0]=':';
11261                                                                 mapname[1]='D';
11262                                                                 mapname[2]='a';
11263                                                                 mapname[3]='t';
11264                                                                 mapname[4]='a';
11265                                                                 mapname[5]=':';
11266                                                                 mapname[6]='M';
11267                                                                 mapname[7]='a';
11268                                                                 mapname[8]='p';
11269                                                                 mapname[9]='s';
11270                                                                 mapname[10]=':';
11271                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
11272                                                                 Loadlevel(mapname);
11273
11274                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11275                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11276                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11277                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11278                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
11279                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11280
11281                                                                 loading=3;
11282                                                         }
11283                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
11284                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
11285                                                                 if(accountprogress[accountactive]>3&&!registered){
11286                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
11287                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11288                                                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
11289                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
11290
11291                                                                         gameon=0;
11292                                                                         mainmenu=12;
11293                                                                         accountprogress[accountactive]=3;
11294
11295                                                                         float gLoc[3]={0,0,0};
11296                                                                         float vel[3]={0,0,0};
11297                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11298                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11299                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11300                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
11301                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
11302                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11303
11304                                                                         flashr=1;
11305                                                                         flashg=0;
11306                                                                         flashb=0;
11307                                                                         flashamount=1;
11308                                                                         flashdelay=1;
11309                                                                 }
11310                                                                 else{
11311                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
11312                                                                                 winfreeze=1;
11313                                                                                 changedelay=-999;
11314                                                                         }
11315                                                                         if(player[0].dead)loading=1;
11316                                                                 }
11317                                                         }
11318                                                 }
11319
11320                                                 if(campaign)
11321                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11322                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11323                                                                         endgame=1;
11324                                                                 }
11325                                                         }
11326                                                         else if(mainmenu==0&&winfreeze){
11327                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11328                                                                         stealthloading=1;
11329                                                                 else stealthloading=0;
11330
11331                                                                 if(!stealthloading){
11332                                                                         float gLoc[3]={0,0,0};
11333                                                                         float vel[3]={0,0,0};
11334                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11335                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11336                                                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11337                                                                         FSOUND_SetVolume(channels[firestartsound], 256);
11338                                                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
11339                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11340
11341                                                                         flashr=1;
11342                                                                         flashg=0;
11343                                                                         flashb=0;
11344                                                                         flashamount=1;
11345                                                                         flashdelay=1;
11346                                                                 }
11347
11348                                                                 startbonustotal=0;
11349
11350                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
11351                                                                 //campaignnumlevels=0;
11352                                                                 //accountcampaignchoicesmade[accountactive]=0;
11353                                                                 ipstream.ignore(256,':');
11354                                                                 ipstream >> campaignnumlevels;
11355                                                                 for(i=0;i<campaignnumlevels;i++){
11356                                                                         ipstream.ignore(256,':');
11357                                                                         ipstream.ignore(256,':');
11358                                                                         ipstream.ignore(256,' ');
11359                                                                         ipstream >> campaignmapname[i];
11360                                                                         ipstream.ignore(256,':');
11361                                                                         ipstream >> campaigndescription[i];
11362                                                                         for(j=0;j<256;j++){
11363                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11364                                                                         }
11365                                                                         ipstream.ignore(256,':');
11366                                                                         ipstream >> campaignchoosenext[i];
11367                                                                         ipstream.ignore(256,':');
11368                                                                         ipstream >> campaignnumnext[i];
11369                                                                         if(campaignnumnext[i])
11370                                                                                 for(j=0;j<campaignnumnext[i];j++){
11371                                                                                         ipstream.ignore(256,':');
11372                                                                                         ipstream >> campaignnextlevel[i][j];
11373                                                                                         campaignnextlevel[i][j]-=1;
11374                                                                                 }
11375                                                                                 ipstream.ignore(256,':');
11376                                                                                 ipstream >> campaignlocationx[i];
11377                                                                                 ipstream.ignore(256,':');
11378                                                                                 ipstream >> campaignlocationy[i];
11379                                                                 }
11380                                                                 ipstream.close();
11381
11382                                                                 for(i=0;i<campaignnumlevels;i++){
11383                                                                         levelvisible[i]=0;
11384                                                                         levelhighlight[i]=0;
11385                                                                 }
11386
11387
11388                                                                 for(i=0;i<campaignnumlevels;i++){
11389                                                                         levelvisible[i]=0;
11390                                                                         levelhighlight[i]=0;
11391                                                                 }
11392
11393                                                                 levelorder[0]=0;
11394                                                                 levelvisible[0]=1;
11395                                                                 if(accountcampaignchoicesmade[accountactive])
11396                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11397                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11398                                                                                 levelvisible[levelorder[i+1]]=1;
11399                                                                         }
11400                                                                         int whichlevelstart;
11401                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11402                                                                         if(whichlevelstart<0){
11403                                                                                 campaignchoicenum=1;
11404                                                                                 campaignchoicewhich[0]=0;
11405                                                                         }
11406                                                                         else
11407                                                                         {
11408                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11409                                                                                 if(campaignchoicenum)
11410                                                                                         for(i=0;i<campaignchoicenum;i++){
11411                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11412                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11413                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11414                                                                                         }
11415                                                                         }
11416
11417                                                                         loading=2;
11418                                                                         loadtime=0;
11419                                                                         targetlevel=7;
11420                                                                         //if(firstload)TickOnceAfter();
11421                                                                         if(!firstload)LoadStuff();
11422                                                                         //else {
11423                                                                         for(i=0;i<255;i++){
11424                                                                                 mapname[i]='\0';
11425                                                                         }
11426                                                                         mapname[0]=':';
11427                                                                         mapname[1]='D';
11428                                                                         mapname[2]='a';
11429                                                                         mapname[3]='t';
11430                                                                         mapname[4]='a';
11431                                                                         mapname[5]=':';
11432                                                                         mapname[6]='M';
11433                                                                         mapname[7]='a';
11434                                                                         mapname[8]='p';
11435                                                                         mapname[9]='s';
11436                                                                         mapname[10]=':';
11437
11438                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11439                                                                         //accountcampaignchoicesmade[accountactive]++;
11440
11441
11442                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11443                                                                         whichchoice=0;
11444                                                                         visibleloading=1;
11445                                                                         stillloading=1;
11446                                                                         Loadlevel(mapname);
11447                                                                         campaign=1;
11448                                                                         mainmenu=0;
11449                                                                         gameon=1;
11450                                                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
11451
11452                                                                         stealthloading=0;
11453                                                         }
11454
11455                                                         if(loading==3)loading=0;
11456
11457                                         }
11458
11459                                         oldmusictype=musictype;
11460         }
11461
11462         facing=0;
11463         facing.z=-1;
11464
11465         facing=DoRotation(facing,-rotation2,0,0);
11466         facing=DoRotation(facing,0,0-rotation,0);
11467         viewerfacing=facing;
11468
11469         brotate=0;
11470         if(!cameramode){
11471                 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;
11472                 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;
11473                 target.y+=.1;
11474                 if(player[0].skeleton.free){
11475                         for(i=0;i<player[0].skeleton.num_joints;i++){
11476                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)                         
11477                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11478                         }
11479                         target.y+=.1;
11480                 }
11481                 if(player[0].skeleton.free!=2&&!autocam){
11482                         cameraspeed=20;
11483                         if(findLengthfast(&player[0].velocity)>400){
11484                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11485                         }
11486                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11487                         coltarget=target-cameraloc;
11488                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11489                         else {
11490                                 Normalise(&coltarget);
11491                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11492                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11493                         }
11494                         if(editorenabled)cameraloc=target;
11495                         cameradist+=multiplier*5;
11496                         if(cameradist>2.3)cameradist=2.3;
11497                         viewer=cameraloc-facing*cameradist;
11498                         colviewer=viewer;
11499                         coltarget=cameraloc;
11500                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11501                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11502                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11503                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11504                                         colviewer=viewer;
11505                                         coltarget=cameraloc;
11506                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;     
11507                                 }
11508                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11509                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11510                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11511                                                 colviewer=viewer;
11512                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11513                                                         viewer=colviewer;
11514                                                 }
11515                                         }
11516                                         cameradist=findDistance(&viewer,&target);
11517                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11518                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11519                                         }
11520                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11521                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11522                                         }
11523                 }
11524                 if(player[0].skeleton.free!=2&&autocam){
11525                         cameraspeed=20;
11526                         if(findLengthfast(&player[0].velocity)>400){
11527                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11528                         }
11529                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11530                         cameradist+=multiplier*5;
11531                         if(cameradist>3.3)cameradist=3.3;
11532                         coltarget=target-cameraloc;
11533                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11534                         else if(findLengthfast(&coltarget)>1)
11535                         {
11536                                 Normalise(&coltarget);
11537                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11538                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11539                         }
11540                         if(editorenabled)cameraloc=target;
11541                         viewer=cameraloc;
11542                         colviewer=viewer;
11543                         coltarget=cameraloc;
11544                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11545                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11546                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11547                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11548                                         colviewer=viewer;
11549                                         coltarget=cameraloc;
11550                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;     
11551                                 }
11552                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11553                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11554                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11555                                                 colviewer=viewer;
11556                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11557                                                         viewer=colviewer;
11558                                                 }
11559                                         }
11560                                         cameradist=findDistance(&viewer,&target);
11561                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11562                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11563                                         }
11564                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11565                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11566                                         }
11567                 }
11568                 if(camerashake>.8)camerashake=.8;
11569                 //if(woozy>10)woozy=10;
11570                 //woozy+=multiplier;
11571                 woozy+=multiplier;
11572                 if(player[0].dead)camerashake=0;
11573                 if(player[0].dead)woozy=0;
11574                 camerashake-=multiplier*2;
11575                 blackout-=multiplier*2;
11576                 //if(player[0].isCrouch())woozy-=multiplier*8;
11577                 if(camerashake<0)camerashake=0;
11578                 if(blackout<0)blackout=0;
11579                 //if(woozy<0)woozy=0;
11580                 if(camerashake){
11581                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11582                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11583                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11584                 }
11585         }
11586 }