]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
Made initial fixes towards building in MinGW for 32-bit Windows
[lugaru.git] / Source / GameTick.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #if PLATFORM_UNIX
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #else
27 #include <direct.h>
28 #endif
29
30 #include <ctime>
31 #include "Game.h"
32
33 using namespace std;
34
35 extern float multiplier;
36 extern XYZ viewer;
37 extern int environment;
38 extern float texscale;
39 extern Terrain terrain;
40 extern FSOUND_SAMPLE    *samp[100];
41 extern int channels[100];
42 extern Sprites sprites;
43 extern int kTextureSize;
44 extern float screenwidth,screenheight;
45 extern float gravity;
46 extern int detail;
47 extern float texdetail;
48 extern Objects objects;
49 extern int slomo;
50 extern float slomodelay;
51 extern bool floatjump;
52 extern float volume;
53 extern Animation animation[animation_count];
54 extern Light light;
55 extern float texdetail;
56 extern GLubyte bloodText[512*512*3];
57 extern GLubyte wolfbloodText[512*512*3];
58 extern float terraindetail;
59 extern float camerashake;
60 extern float woozy;
61 extern float blackout;
62 extern bool cellophane;
63 extern bool musictoggle;
64 extern int difficulty;
65 extern Weapons weapons;
66 extern Person player[maxplayers];
67 extern int numplayers;
68 extern int bloodtoggle;
69 extern bool invertmouse;
70 extern float windvar;
71 extern float precipdelay;
72 extern XYZ viewerfacing;
73 extern bool ambientsound;
74 extern bool mousejump;
75 extern float viewdistance;
76 extern bool freeze;
77 extern bool autoslomo;
78 extern int newnetmessages;
79 extern char netmessages[256];
80 extern bool keyboardfrozen;
81 extern int netdatanew;
82 extern bool loadingstuff;
83 extern char mapname[256];
84 extern XYZ windvector;
85 extern bool buttons[3];
86 extern bool debugmode;
87 static int music1;
88 extern int mainmenu;
89 extern int oldmainmenu;
90 extern bool visibleloading;
91 extern int loadscreencolor;
92 extern float flashamount,flashr,flashg,flashb;
93 extern int flashdelay;
94 extern XYZ envsound[30];
95 extern float envsoundvol[30];
96 extern int numenvsounds;
97 extern float envsoundlife[30];
98 extern float usermousesensitivity;
99 extern bool ismotionblur;
100 extern bool foliage;
101 extern bool trilinear;
102 extern bool damageeffects;
103 extern bool showpoints;
104 extern bool texttoggle;
105 extern bool alwaysblur;
106 extern float gamespeed;
107 extern bool decals;
108 extern bool vblsync;
109 extern bool immediate;
110 extern bool velocityblur;
111 extern int bonus;
112 extern int oldbonus;
113 extern float bonusvalue;
114 extern float bonustotal;
115 extern float bonustime;
116 extern float startbonustotal;
117 extern float tintr,tintg,tintb;
118 extern float bonusnum[100];
119 extern bool skyboxtexture;
120 extern float skyboxr;
121 extern float skyboxg;
122 extern float skyboxb;
123 extern float skyboxlightr;
124 extern float skyboxlightg;
125 extern float skyboxlightb;
126 extern float fadestart;
127 extern float slomospeed;
128 extern float slomofreq;
129 extern int tutoriallevel;
130 extern float smoketex;
131 extern float tutorialstagetime;
132 extern int tutorialstage;
133 extern float tutorialmaxtime;
134 extern float tutorialsuccess;
135 extern bool againbonus;
136 extern bool reversaltrain;
137 extern bool canattack;
138 extern bool cananger;
139 extern float damagedealt;
140 extern float damagetaken;
141 extern int maptype;
142 extern int editoractive;
143 extern int editorpathtype;
144 extern bool oldbuttons[3];
145
146 extern float hostiletime;
147
148 extern bool gamestarted;
149
150 extern int numhotspots;
151 extern int winhotspot;
152 extern int windialogue;
153 extern int killhotspot;
154 extern XYZ hotspot[40];
155 extern int hotspottype[40];
156 extern float hotspotsize[40];
157 extern char hotspottext[40][256];
158 extern int currenthotspot;
159
160 extern int kBitsPerPixel;
161 extern int hostile;
162
163 extern int numaccounts;
164 extern int accountactive;
165 extern int accountdifficulty[10];
166 extern int accountprogress[10];
167 extern float accountpoints[10];
168 extern float accounthighscore[10][50];
169 extern float accountfasttime[10][50];
170 extern bool accountunlocked[10][60];
171 extern char accountname[10][256];
172
173 extern bool stillloading;
174 extern bool winfreeze;
175
176 extern int numfalls;
177 extern int numflipfail;
178 extern int numseen;
179 extern int numstaffattack;
180 extern int numswordattack;
181 extern int numknifeattack;
182 extern int numunarmedattack;
183 extern int numescaped;
184 extern int numflipped;
185 extern int numwallflipped;
186 extern int numthrowkill;
187 extern int numafterkill;
188 extern int numreversals;
189 extern int numattacks;
190 extern int maxalarmed;
191 extern int numresponded;
192
193 extern int numdialogues;
194 extern int numdialogueboxes[max_dialogues];
195 extern int dialoguetype[max_dialogues];
196 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
197 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
198 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
199 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
200 extern char dialoguename[max_dialogues][max_dialoguelength][64];
201 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
202 extern XYZ participantlocation[max_dialogues][10];
203 extern int participantfocus[max_dialogues][max_dialoguelength];
204 extern int participantaction[max_dialogues][max_dialoguelength];
205 extern float participantrotation[max_dialogues][10];
206 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
207 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
208 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
209 extern int indialogue;
210 extern int whichdialogue;
211 extern int directing;
212 extern float dialoguetime;
213 extern int dialoguegonethrough[20];
214
215 extern bool campaign;
216
217 extern float oldgamespeed;
218
219 extern float accountcampaignhighscore[10];
220 extern float accountcampaignfasttime[10];
221 extern float accountcampaignscore[10];
222 extern float accountcampaigntime[10];
223
224 extern int accountcampaignchoicesmade[10];
225 extern int accountcampaignchoices[10][5000];
226 /********************> Tick() <*****/
227 extern FSOUND_STREAM * strm[20];
228 extern "C"      void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
229 extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
230
231 extern void ScreenShot(const char * fname);
232 void Screenshot (void)
233 {
234         char temp[1024];
235         time_t  t = time(NULL);
236         struct  tm *tme = localtime(&t);
237         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);
238
239         #if defined(_WIN32)
240         mkdir("Screenshots");
241         #else
242         mkdir("Screenshots", S_IRWXU);
243         #endif
244
245         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
246
247         /*FSSpec                                MAC_file;
248         GraphicsExportComponent QT_exporter;
249         OSErr                           MAC_error_code;
250         CGrafPtr                        MAC_currentPort;
251         GDHandle                        MAC_currentDevice;
252         unsigned char*          MAC_pixels;
253         Rect                            MAC_picture_rectangle;
254         GWorldPtr                       MAC_offscreen_graphics_port;
255
256         static int numscreenshots=0;
257
258         // Make an FSSpec
259         static char buf[256];
260         if(numscreenshots==0){
261         buf[0]=26;
262         buf[1]=':';
263         buf[2]='S';
264         buf[3]='c';
265         buf[4]='r';
266         buf[5]='e';
267         buf[6]='e';
268         buf[7]='n';
269         buf[8]='s';
270         buf[9]='h';
271         buf[10]='o';
272         buf[11]='t';
273         buf[12]='s';
274         buf[13]=':';
275         buf[14]='S';
276         buf[15]='c';
277         buf[16]='r';
278         buf[17]='e';
279         buf[18]='e';
280         buf[19]='n';
281         buf[20]='s';
282         buf[21]='h';
283         buf[22]='o';
284         buf[23]='t';
285         buf[24]='0';
286         buf[25]='0';
287         buf[26]='0';
288         }
289
290         FInfo *fndrInfo;
291         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
292         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
293         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
294         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
295         numscreenshots++;
296         buf[26]++;
297         if(buf[26]==':'){
298         buf[26]='0';
299         buf[25]++;
300         if(buf[25]==':'){
301         buf[25]='0';
302         buf[24]++;
303         if(buf[24]==':'){
304         buf[24]='9';
305         buf[25]='9';
306         buf[26]='9';
307         }
308         }
309         }
310         }
311         }
312
313
314         // Get the GWorld
315         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
316         //assert(MAC_gWorld != NULL);
317
318         // Allocate memory for loading image
319         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
320         if (MAC_pixels == NULL) {
321         //UTIL_Error("Could not create Texture data.");
322         return;
323         }
324
325         // Get GWorld
326         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
327
328         // Make a picture Rectangle
329         MAC_picture_rectangle.left = 0;
330         MAC_picture_rectangle.right = screenwidth;
331         MAC_picture_rectangle.top = 0;
332         MAC_picture_rectangle.bottom = screenheight;
333
334         // Create new offscreen GWorld
335         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
336         if (MAC_error_code)     {
337         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
338         delete MAC_pixels;
339         //UTIL_Error("Could not create offscreen GWorld. ");
340         return;
341
342         }
343
344         // Copy OpenGL Context to new GWorld
345         glReadBuffer(GL_FRONT);
346         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
347
348         // Swizzle texture
349         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
350         unsigned char temp = MAC_pixels[byte+0];
351         MAC_pixels[byte+0] = MAC_pixels[byte+3];
352         MAC_pixels[byte+3] = MAC_pixels[byte+2];
353         MAC_pixels[byte+2] = MAC_pixels[byte+1];
354         MAC_pixels[byte+1] = temp;
355         }
356
357         // Flip the image  :(   This could probably be optimized
358         int vert;
359         int src_index;
360         int dst_index;
361         unsigned char temp;
362         for (int horz = 0; horz < screenwidth; ++horz)
363         for (vert = 0; vert < screenheight / 2; ++vert) {
364         src_index = (screenwidth * vert + horz) * 4;
365         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
366
367         temp=MAC_pixels[src_index+0];
368         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
369         MAC_pixels[dst_index+0]=temp;
370
371         temp=MAC_pixels[src_index+1];
372         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
373         MAC_pixels[dst_index+1]=temp;
374
375         temp=MAC_pixels[src_index+2];
376         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
377         MAC_pixels[dst_index+2]=temp;
378
379         temp=MAC_pixels[src_index+3];
380         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
381         MAC_pixels[dst_index+3]=temp;
382         }
383
384
385
386         // Export the Gworld
387         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
388         if (MAC_error_code) {
389         //UTIL_Warning("Unable to export screenshot.");
390         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
391         ::DisposeGWorld(MAC_offscreen_graphics_port);
392         delete MAC_pixels;
393         return;
394         }
395
396         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
397         if (MAC_error_code) {
398         ::CloseComponent(QT_exporter);
399         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
400         ::DisposeGWorld(MAC_offscreen_graphics_port);
401         delete MAC_pixels;
402         //UTIL_Warning("Unable to export screenshot.");
403         return;
404         }
405
406         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
407         if (MAC_error_code) {
408         ::CloseComponent(QT_exporter);
409         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
410         ::DisposeGWorld(MAC_offscreen_graphics_port);
411         delete MAC_pixels;
412         //UTIL_Warning("Unable to export screenshot.");
413         return;
414         }
415
416         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
417         if (MAC_error_code) {
418         ::CloseComponent(QT_exporter);
419         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
420         ::DisposeGWorld(MAC_offscreen_graphics_port);
421         delete MAC_pixels;
422         //UTIL_Warning("Unable to export screenshot.");
423         return;
424         }
425
426         ::CloseComponent(QT_exporter);
427         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
428         ::DisposeGWorld(MAC_offscreen_graphics_port);
429
430         delete MAC_pixels;*/
431 }
432
433
434
435 void    Game::SetUpLighting(){
436         if(environment==snowyenvironment){
437                 light.color[0]=.65;
438                 light.color[1]=.65;
439                 light.color[2]=.7;
440                 light.ambient[0]=.4;
441                 light.ambient[1]=.4;
442                 light.ambient[2]=.44;
443         }
444         if(environment==desertenvironment){
445                 light.color[0]=.95;
446                 light.color[1]=.95;
447                 light.color[2]=.95;
448                 light.ambient[0]=.4;
449                 light.ambient[1]=.35;
450                 light.ambient[2]=.3;
451         }
452
453         if(environment==grassyenvironment){
454                 light.color[0]=.95;
455                 light.color[1]=.95;
456                 light.color[2]=1;
457                 light.ambient[0]=.4;
458                 light.ambient[1]=.4;
459                 light.ambient[2]=.44;
460         }
461         if(!skyboxtexture){
462                 light.color[0]=1;
463                 light.color[1]=1;
464                 light.color[2]=1;
465                 light.ambient[0]=.4;
466                 light.ambient[1]=.4;
467                 light.ambient[2]=.4;
468         }
469         float average;
470         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
471         light.color[0]*=(skyboxlightr+average)/2;
472         light.color[1]*=(skyboxlightg+average)/2;
473         light.color[2]*=(skyboxlightb+average)/2;
474         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
475         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
476         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
477         /*
478         light.ambient[0]=0;
479         light.ambient[1]=0;
480         light.ambient[2]=0;     */
481 }
482
483 int Game::findPathDist(int start,int end){
484         int i,j,k,smallestcount,count,connected;
485         int last,last2,last3,last4;
486         int closest;
487
488         smallestcount=1000;
489         for(i=0;i<50;i++){
490                 count=0;
491                 last=start;
492                 last2=-1;
493                 last3=-1;
494                 last4=-1;
495                 while(last!=end&&count<30){
496                         closest=-1;
497                         for(j=0;j<numpathpoints;j++){
498                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
499                                 {
500                                         connected=0;
501                                         if(numpathpointconnect[j])
502                                                 for(k=0;k<numpathpointconnect[j];k++){
503                                                         if(pathpointconnect[j][k]==last)connected=1;
504                                                 }
505                                                 if(!connected)
506                                                         if(numpathpointconnect[last])
507                                                                 for(k=0;k<numpathpointconnect[last];k++){
508                                                                         if(pathpointconnect[last][k]==j)connected=1;
509                                                                 }
510                                                                 if(connected)
511                                                                         if(closest==-1||Random()%2==0){
512                                                                                 closest=j;
513                                                                         }
514                                 }
515                         }
516                         last4=last3;
517                         last3=last2;
518                         last2=last;
519                         last=closest;
520                         count++;
521                 }
522                 if(count<smallestcount)smallestcount=count;
523         }
524         return smallestcount;
525 }
526
527 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
528         static XYZ colpoint,colviewer,coltarget;
529         static float minx,minz,maxx,maxz,miny,maxy;
530         static int i;
531
532         //startpoint.y+=.7;
533         //endpoint.y+=.7;
534         //startpoint.y-=.1;
535         //endpoint.y-=.1;
536
537         minx=startpoint.x;
538         if(minx>endpoint.x)minx=endpoint.x;
539         miny=startpoint.y;
540         if(miny>endpoint.y)miny=endpoint.y;
541         minz=startpoint.z;
542         if(minz>endpoint.z)minz=endpoint.z;
543
544         maxx=startpoint.x;
545         if(maxx<endpoint.x)maxx=endpoint.x;
546         maxy=startpoint.y;
547         if(maxy<endpoint.y)maxy=endpoint.y;
548         maxz=startpoint.z;
549         if(maxz<endpoint.z)maxz=endpoint.z;
550
551         minx-=1;
552         miny-=1;
553         minz-=1;
554         maxx+=1;
555         maxy+=1;
556         maxz+=1;
557
558         for(i=0;i<objects.numobjects;i++){
559                 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){
560                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
561                                 colviewer=startpoint;
562                                 coltarget=endpoint;
563                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
564                         }
565                 }
566         }
567
568         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
569
570         return -1;
571 }
572
573 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
574         static XYZ colpoint,colviewer,coltarget;
575         static float minx,minz,maxx,maxz,miny,maxy;
576         static int i;
577
578         //startpoint.y+=.7;
579         //endpoint.y+=.7;
580         //startpoint.y-=.1;
581         //endpoint.y-=.1;
582
583         minx=startpoint.x;
584         if(minx>endpoint.x)minx=endpoint.x;
585         miny=startpoint.y;
586         if(miny>endpoint.y)miny=endpoint.y;
587         minz=startpoint.z;
588         if(minz>endpoint.z)minz=endpoint.z;
589
590         maxx=startpoint.x;
591         if(maxx<endpoint.x)maxx=endpoint.x;
592         maxy=startpoint.y;
593         if(maxy<endpoint.y)maxy=endpoint.y;
594         maxz=startpoint.z;
595         if(maxz<endpoint.z)maxz=endpoint.z;
596
597         minx-=1;
598         miny-=1;
599         minz-=1;
600         maxx+=1;
601         maxy+=1;
602         maxz+=1;
603
604         if(what!=1000){
605                 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){
606                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
607                                 colviewer=startpoint;
608                                 coltarget=endpoint;
609                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
610                         }
611                 }
612         }
613
614         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
615
616         return -1;
617 }
618
619 void    Game::Setenvironment(int which)
620 {
621         LOGFUNC;
622
623         LOG(" Setting environment...");
624
625         float temptexdetail;
626         environment=which;
627 /*
628         FSOUND_SetPaused(channels[music1snow], true);
629         FSOUND_SetPaused(channels[music1grass], true);
630         FSOUND_SetPaused(channels[music1desert], true);
631         FSOUND_SetPaused(channels[wind], true);
632         FSOUND_SetPaused(channels[desertambient], true);
633 */
634         FSOUND_SetPaused(channels[stream_music1snow], true);
635         FSOUND_SetPaused(channels[stream_music1grass], true);
636         FSOUND_SetPaused(channels[stream_music1desert], true);
637         FSOUND_SetPaused(channels[stream_wind], true);
638         FSOUND_SetPaused(channels[stream_desertambient], true);
639
640
641         if(environment==snowyenvironment){
642                 windvector=0;
643                 windvector.z=3;
644                 if(ambientsound){
645                         //PlaySoundEx( wind, samp[wind], NULL, true);
646                         PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
647                         FSOUND_SetPaused(channels[stream_wind], false);
648                         FSOUND_SetVolume(channels[stream_wind], 256);
649                 }
650
651                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
652                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
653                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
654                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
655
656                 FSOUND_Sample_Free(samp[footstepsound]);
657                 FSOUND_Sample_Free(samp[footstepsound2]);
658                 FSOUND_Sample_Free(samp[footstepsound3]);
659                 FSOUND_Sample_Free(samp[footstepsound4]);
660                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
661                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
662                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
663                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
664                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
665                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
666                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
667                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
668
669                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
670
671                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
672
673                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
674
675
676
677
678                 temptexdetail=texdetail;
679                 if(texdetail>1)texdetail=4;
680                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
681                         ":Data:Textures:Skybox(snow):Left.jpg",
682                         ":Data:Textures:Skybox(snow):Back.jpg",
683                         ":Data:Textures:Skybox(snow):Right.jpg",
684                         ":Data:Textures:Skybox(snow):Up.jpg",
685                         ":Data:Textures:Skybox(snow):Down.jpg",
686                         ":Data:Textures:Skybox(snow):Cloud.jpg",
687                         ":Data:Textures:Skybox(snow):Reflect.jpg");
688
689
690
691
692                 texdetail=temptexdetail;
693         }
694         if(environment==desertenvironment){
695                 windvector=0;
696                 windvector.z=2;
697                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
698                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
699                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
700                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
701
702
703                 if(ambientsound){
704                         //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
705                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
706                         FSOUND_SetPaused(channels[stream_desertambient], false);
707                         FSOUND_SetVolume(channels[stream_desertambient], 256);
708                 }
709
710                 FSOUND_Sample_Free(samp[footstepsound]);
711                 FSOUND_Sample_Free(samp[footstepsound2]);
712                 FSOUND_Sample_Free(samp[footstepsound3]);
713                 FSOUND_Sample_Free(samp[footstepsound4]);
714                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
715                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
716                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
717                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
718                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
719                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
720                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
721                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
722
723                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
724
725                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
726
727                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
728
729
730
731                 temptexdetail=texdetail;
732                 if(texdetail>1)texdetail=4;
733                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
734                         ":Data:Textures:Skybox(sand):Left.jpg",
735                         ":Data:Textures:Skybox(sand):Back.jpg",
736                         ":Data:Textures:Skybox(sand):Right.jpg",
737                         ":Data:Textures:Skybox(sand):Up.jpg",
738                         ":Data:Textures:Skybox(sand):Down.jpg",
739                         ":Data:Textures:Skybox(sand):Cloud.jpg",
740                         ":Data:Textures:Skybox(sand):Reflect.jpg");
741
742
743
744
745                 texdetail=temptexdetail;
746         }
747         if(environment==grassyenvironment){
748                 windvector=0;
749                 windvector.z=2;
750                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
751                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
752                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
753                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
754
755                 if(ambientsound){
756                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
757                         FSOUND_SetPaused(channels[stream_wind], false);
758                         FSOUND_SetVolume(channels[stream_wind], 100);
759                 }
760
761                 FSOUND_Sample_Free(samp[footstepsound]);
762                 FSOUND_Sample_Free(samp[footstepsound2]);
763                 FSOUND_Sample_Free(samp[footstepsound3]);
764                 FSOUND_Sample_Free(samp[footstepsound4]);
765                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass1.ogg", FSOUND_HW3D, 0, 0);
766                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass2.ogg", FSOUND_HW3D, 0, 0);
767                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
768                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
769                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
770                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
771                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
772                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
773
774                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
775
776                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
777
778                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
779
780
781
782                 temptexdetail=texdetail;
783                 if(texdetail>1)texdetail=4;
784                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
785                         ":Data:Textures:Skybox(grass):Left.jpg",
786                         ":Data:Textures:Skybox(grass):Back.jpg",
787                         ":Data:Textures:Skybox(grass):Right.jpg",
788                         ":Data:Textures:Skybox(grass):Up.jpg",
789                         ":Data:Textures:Skybox(grass):Down.jpg",
790                         ":Data:Textures:Skybox(grass):Cloud.jpg",
791                         ":Data:Textures:Skybox(grass):Reflect.jpg");
792
793
794
795                 texdetail=temptexdetail;
796         }
797         temptexdetail=texdetail;
798         texdetail=1;
799         terrain.load(":Data:Textures:heightmap.png");
800
801         texdetail=temptexdetail;
802 }
803
804
805 void    Game::Loadlevel(int which){
806         stealthloading=0;
807
808         if(which==0)Loadlevel((char *)":Data:Maps:map1");
809         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
810         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
811         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
812         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
813         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
814         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
815         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
816         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
817         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
818         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
819         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
820         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
821         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
822         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
823         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
824         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
825         else Loadlevel((char *)":Data:Maps:mapsave");
826
827         whichlevel=which;
828 }
829
830 /*char * Game::MD5_string (unsigned char *string){
831 char temp[50];
832 char temp2[100];
833
834 strcpy(temp2,(const char *)string);
835 strcat((char *)temp2,(const char *)"Lugaru");
836 sprintf (temp, "%d",strlen((char *)temp2));
837 strcat((char *)temp2,temp);
838
839 MD5 context;
840 unsigned int len = strlen ( (char *)temp2);
841
842 context.update   ((unsigned char *)temp2, len);
843 context.finalize ();
844
845 return context.hex_digest();
846 }*/
847
848
849
850 void    Game::Loadlevel(char *name){
851         int i,j,k,l,m;
852         static int oldlevel;
853         int templength;
854         float lamefloat;
855         int lameint;
856
857         float headprop,legprop,armprop,bodyprop;
858
859         LOGFUNC;
860
861         LOG(std::string("Loading level...") + name);
862
863         if(!gameon)visibleloading=1;
864
865         if(stealthloading)visibleloading=0;
866
867         if(!stillloading)loadtime=0;
868         gamestarted=1;
869
870         numenvsounds=0;
871         //visibleloading=1;
872         if(tutoriallevel!=-1)tutoriallevel=0;
873         else tutoriallevel=1;
874
875         if(tutoriallevel==1)tutorialstage=0;
876         if(tutorialstage==0){
877                 tutorialstagetime=0;
878                 tutorialmaxtime=1;
879         }
880         loadingstuff=1;
881         if(!firstload){
882                 oldlevel=50;
883         }
884         FSOUND_SetPaused(channels[whooshsound], true);
885         FSOUND_SetPaused(channels[stream_firesound], true);
886
887         int mapvers;
888         FILE                    *tfile;
889         tfile=fopen( name, "rb" );
890         if(tfile)
891         {
892                 FSOUND_SetPaused(channels[stream_firesound], true);
893
894
895                 scoreadded=0;
896                 windialogue=0;
897
898                 hostiletime=0;
899
900                 won=0;
901
902                 //campaign=0;
903                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
904
905                 numdialogues=0;
906
907                 for(i=0;i<20;i++)
908                 {
909                         dialoguegonethrough[i]=0;
910                 }
911
912                 indialogue=-1;
913                 cameramode=0;
914
915                 damagedealt=0;
916                 damagetaken=0;
917
918                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
919
920                 if(difficulty!=2)minimap=1;
921                 else minimap=0;
922
923                 numhotspots=0;
924                 currenthotspot=-1;
925                 bonustime=1;
926
927                 skyboxtexture=1;
928                 skyboxr=1;
929                 skyboxg=1;
930                 skyboxb=1;
931
932                 freeze=0;
933                 winfreeze=0;
934
935                 for(i=0;i<100;i++)
936                 {
937                         bonusnum[i]=0;
938                 }
939
940                 numfalls=0;
941                 numflipfail=0;
942                 numseen=0;
943                 numstaffattack=0;
944                 numswordattack=0;
945                 numknifeattack=0;
946                 numunarmedattack=0;
947                 numescaped=0;
948                 numflipped=0;
949                 numwallflipped=0;
950                 numthrowkill=0;
951                 numafterkill=0;
952                 numreversals=0;
953                 numattacks=0;
954                 maxalarmed=0;
955                 numresponded=0;
956
957                 bonustotal=startbonustotal;
958                 bonus=0;
959                 gameon=1;
960                 changedelay=0;
961                 if(console)
962                 {
963                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
964                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
965                         FSOUND_SetPaused(channels[consolesuccesssound], false);
966                         freeze=0;
967                         console=0;
968                 }
969
970                 if(!stealthloading)
971                 {
972                         terrain.numdecals=0;
973                         sprites.numsprites=0;
974                         for(i=0;i<objects.numobjects;i++)
975                         {
976                                 objects.model[i].numdecals=0;
977                         }
978
979                         j=objects.numobjects;
980                         for(i=0;i<j;i++)
981                         {
982                                 objects.DeleteObject(0);
983                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
984                         }
985
986                         for(i=0;i<subdivision;i++)
987                         {
988                                 for(j=0;j<subdivision;j++)
989                                 {
990                                         terrain.patchobjectnum[i][j]=0;
991                                 }
992                         }
993                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
994                 }
995
996                 weapons.numweapons=0;
997
998                 funpackf(tfile, "Bi", &mapvers);
999                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
1000                 else indemo=0;
1001                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1002                 else maptype=mapkilleveryone;
1003                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1004                 else hostile=1;
1005                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1006                 else
1007                 {
1008                         viewdistance=100;
1009                         fadestart=.6;
1010                 }
1011                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1012                 else
1013                 {
1014                         skyboxtexture=1;
1015                         skyboxr=1;
1016                         skyboxg=1;
1017                         skyboxb=1;
1018                 }
1019                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1020                 else
1021                 {
1022                         skyboxlightr=skyboxr;
1023                         skyboxlightg=skyboxg;
1024                         skyboxlightb=skyboxb;
1025                 }
1026                 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);
1027                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1028                 player[0].originalcoords=player[0].coords;
1029                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1030                 {
1031                         for(j=0;j<player[0].num_weapons;j++)
1032                         {
1033                                 player[0].weaponids[j]=weapons.numweapons;
1034                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1035                                 weapons.owner[weapons.numweapons]=0;
1036                                 weapons.numweapons++;
1037                         }
1038                 }
1039
1040                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1041
1042                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1043                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1044                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1045                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1046
1047                 funpackf(tfile, "Bi", &player[0].numclothes);
1048
1049                 if(mapvers>=9)
1050                 {
1051                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1052                 }
1053                 else
1054                 {
1055                         player[0].whichskin=0;
1056                         player[0].creature=rabbittype;
1057                 }
1058
1059                 for(i=0;i<max_dialogues;i++)
1060                 {
1061                         for(j=0;j<max_dialoguelength;j++)
1062                         {
1063                                 for(k=0;k<128;k++)
1064                                 {
1065                                         dialoguetext[i][j][k]='\0';
1066                                 }
1067                                 for(k=0;k<64;k++)
1068                                 {
1069                                         dialoguename[i][j][k]='\0';
1070                                 }
1071                         }
1072                 }
1073
1074                 player[0].lastattack=-1;
1075                 player[0].lastattack2=-1;
1076                 player[0].lastattack3=-1;
1077
1078                 if(mapvers>=8)
1079                 {
1080                         funpackf(tfile, "Bi", &numdialogues);
1081                         if(numdialogues)
1082                         {
1083                                 for(k=0;k<numdialogues;k++)
1084                                 {
1085                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1086                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1087                                         for(l=0;l<10;l++)
1088                                         {
1089                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1090                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1091                                         }
1092                                         if(numdialogueboxes)
1093                                         {
1094                                                 for(l=0;l<numdialogueboxes[k];l++)
1095                                                 {
1096                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1097                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1098                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1099                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1100                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1101
1102                                                         bool doneread;
1103
1104                                                         funpackf(tfile, "Bi",&templength);
1105                                                         if(templength>128||templength<=0)templength=128;
1106                                                         for(m=0;m<templength;m++){
1107                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1108                                                                 if(dialoguetext[k][l][m]=='\0')break;
1109                                                         }
1110
1111                                                         funpackf(tfile, "Bi",&templength);
1112                                                         if(templength>64||templength<=0)templength=64;
1113                                                         for(m=0;m<templength;m++){
1114                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1115                                                                 if(dialoguename[k][l][m]=='\0'){
1116                                                                         break;
1117                                                                 }
1118                                                         }
1119                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1120                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1121                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1122
1123                                                         for(m=0;m<10;m++)
1124                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1125
1126                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1127                                                 }
1128                                         }
1129                                 }
1130                         }
1131                 }
1132                 else numdialogues=0;
1133
1134                 if(player[0].numclothes)
1135                 {
1136                         for(k=0;k<player[0].numclothes;k++)
1137                         {
1138                                 funpackf(tfile, "Bi", &templength);
1139                                 for(l=0;l<templength;l++)
1140                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1141                                 player[0].clothes[k][templength]='\0';
1142                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1143                         }
1144                 }
1145
1146                 funpackf(tfile, "Bi", &environment);
1147
1148                 funpackf(tfile, "Bi", &objects.numobjects);
1149                 if(objects.numobjects)
1150                 {
1151                         for(i=0;i<objects.numobjects;i++)
1152                         {
1153                                 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]);
1154                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1155                         }
1156                 }
1157
1158                 if(mapvers>=7)
1159                 {
1160                         funpackf(tfile, "Bi", &numhotspots);
1161                         if(numhotspots)
1162                         {
1163                                 for(i=0;i<numhotspots;i++)
1164                                 {
1165                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1166                                         funpackf(tfile, "Bi", &templength);
1167                                         if(templength)
1168                                                 for(l=0;l<templength;l++)
1169                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1170                                         hotspottext[i][templength]='\0';
1171                                         if(hotspottype[i]==-111)indemo=1;
1172                                 }
1173                         }
1174                 }
1175                 else numhotspots=0;
1176
1177                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1178
1179                 if(!stealthloading)
1180                 {
1181                         objects.center=0;
1182                         for(i=0;i<objects.numobjects;i++)
1183                         {
1184                                 objects.center+=objects.position[i];
1185                         }
1186                         objects.center/=objects.numobjects;
1187
1188
1189                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1190
1191                         float maxdistance=0;
1192                         float tempdist;
1193                         int whichclosest;
1194                         for(i=0;i<objects.numobjects;i++)
1195                         {
1196                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1197                                 if(tempdist>maxdistance)
1198                                 {
1199                                         whichclosest=i;
1200                                         maxdistance=tempdist;
1201                                 }
1202                         }
1203                         objects.radius=fast_sqrt(maxdistance);
1204                 }
1205
1206                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1207                 //mapcenter=objects.center;
1208                 //mapradius=objects.radius;
1209
1210                 funpackf(tfile, "Bi", &numplayers);
1211                 int howmanyremoved=0;
1212                 bool removeanother=0;
1213                 if(numplayers>1&&numplayers<maxplayers)
1214                 {
1215                         for(i=1;i<numplayers;i++)
1216                         {
1217                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1218                                 removeanother=0;
1219
1220                                 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);
1221                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1222                                 else player[i-howmanyremoved].howactive=typeactive;
1223                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1224                                 else player[i-howmanyremoved].scale=-1;
1225                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1226                                 else player[i-howmanyremoved].immobile=0;
1227                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1228                                 else player[i-howmanyremoved].rotation=0;
1229                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1230                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1231                                         removeanother=1;
1232                                         howmanyremoved++;
1233                                 }
1234                                 if(!removeanother)
1235                                 {
1236                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1237                                         {
1238                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1239                                                 {
1240                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1241                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1242                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1243                                                         weapons.numweapons++;
1244                                                 }
1245                                         }
1246                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1247                                         //player[i-howmanyremoved].numwaypoints=10;
1248                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1249                                         {
1250                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1251                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1252                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1253                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1254                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1255                                         }
1256
1257                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1258                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1259
1260                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1261                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1262                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1263                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1264
1265                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1266                                         else
1267                                         {
1268                                                 headprop=1;
1269                                                 bodyprop=1;
1270                                                 armprop=1;
1271                                                 legprop=1;
1272                                         }
1273                                         if(player[i-howmanyremoved].creature==wolftype)
1274                                         {
1275                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1276                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1277                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1278                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1279                                         }
1280
1281                                         if(player[i-howmanyremoved].creature==rabbittype)
1282                                         {
1283                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1284                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1285                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1286                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1287                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1288                                         }
1289
1290                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1291                                         if(player[i-howmanyremoved].numclothes)
1292                                         {
1293                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1294                                                 {
1295                                                         int templength;
1296                                                         funpackf(tfile, "Bi", &templength);
1297                                                         for(l=0;l<templength;l++)
1298                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1299                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1300                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1301                                                 }
1302                                         }
1303                                 }
1304                         }
1305                 }
1306                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1307
1308                 numplayers-=howmanyremoved;
1309                 funpackf(tfile, "Bi", &numpathpoints);
1310                 if(numpathpoints>30||numpathpoints<0)
1311                         numpathpoints=0;
1312                 if(numpathpoints)
1313                 {
1314                         for(j=0;j<numpathpoints;j++)
1315                         {
1316                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1317                                 for(k=0;k<numpathpointconnect[j];k++){
1318                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1319                                 }
1320                         }
1321                 }
1322                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1323
1324                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1325
1326                 SetUpLighting();
1327                 if(environment!=oldenvironment)Setenvironment(environment);
1328                 oldenvironment=environment;
1329
1330                 if(!stealthloading)
1331                 {
1332                         j=objects.numobjects;
1333                         objects.numobjects=0;
1334                         for(i=0;i<j;i++)
1335                         {
1336                                 //if(objects.type[i]!=spiketype)
1337                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1338                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1339                         }
1340
1341                         //if(skyboxtexture){
1342                         terrain.DoShadows();
1343                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1344                         objects.DoShadows();
1345                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1346                         /*}
1347                         else terrain.DoLighting();
1348                         */
1349                 }
1350
1351                 fclose(tfile);
1352
1353                 oldlevel=whichlevel;
1354
1355
1356                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1357                 for(i=0;i<numplayers;i++)
1358                 {
1359                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1360                         player[i].burnt=0;
1361                         player[i].bled=0;
1362                         player[i].onfire=0;
1363                         if(i==0||player[i].scale<0)player[i].scale=.2;
1364                         player[i].skeleton.free=0;
1365                         player[i].skeleton.id=i;
1366                         //if(Random()%2==0)player[i].creature=wolftype;
1367                         //else player[i].creature=rabbittype;
1368                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1369                         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);
1370                         else
1371                         {
1372                                 if(player[i].creature!=wolftype){
1373                                         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);
1374                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1375                                 }
1376                                 if(player[i].creature==wolftype){
1377                                         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);
1378                                 }
1379                         }
1380
1381
1382                         int texsize;
1383                         texsize=512*512*3/texdetail/texdetail;
1384                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1385                         //player[i].skeleton.skinText.resize(texsize);
1386
1387                         if(player[i].creature==rabbittype)
1388                         {
1389                                 if(player[i].whichskin==0){
1390                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1391                                 }
1392                                 else if(player[i].whichskin==1){
1393                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1394                                 }
1395                                 else if(player[i].whichskin==2){
1396                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1397                                 }
1398                                 else if(player[i].whichskin==3){
1399                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1400                                 }
1401                                 else if(player[i].whichskin==4){
1402                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1403                                 }
1404                                 else if(player[i].whichskin==5){
1405                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1406                                 }
1407                                 else if(player[i].whichskin==6){
1408                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1409                                 }
1410                                 else if(player[i].whichskin==7){
1411                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1412                                 }
1413                                 else if(player[i].whichskin==8){
1414                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1415                                 }
1416                                 else if(player[i].whichskin==9){
1417                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1418                                 }
1419                         }
1420                         if(player[i].creature==wolftype)
1421                         {
1422                                 //k=abs(Random()%3);
1423                                 if(player[i].whichskin==0){
1424                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1425                                 }
1426                                 else if(player[i].whichskin==1){
1427                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1428                                 }
1429                                 else if(player[i].whichskin==2){
1430                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1431                                 }
1432                         }
1433
1434                         if(player[i].numclothes)
1435                         {
1436                                 for(j=0;j<player[i].numclothes;j++)
1437                                 {
1438                                         tintr=player[i].clothestintr[j];
1439                                         tintg=player[i].clothestintg[j];
1440                                         tintb=player[i].clothestintb[j];
1441                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1442                                 }
1443                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1444                         }
1445
1446                         player[i].currentanimation=bounceidleanim;
1447                         player[i].targetanimation=bounceidleanim;
1448                         player[i].currentframe=0;
1449                         player[i].targetframe=1;
1450                         player[i].target=0;
1451                         player[i].speed=1+(float)(Random()%100)/1000;
1452                         if(difficulty==0)player[i].speed-=.2;
1453                         if(difficulty==1)player[i].speed-=.1;
1454
1455                         player[i].velocity=0;
1456                         player[i].oldcoords=player[i].coords;
1457                         player[i].realoldcoords=player[i].coords;
1458
1459                         player[i].id=i;
1460                         player[i].skeleton.id=i;
1461                         player[i].updatedelay=0;
1462                         player[i].normalsupdatedelay=0;
1463
1464                         player[i].aitype=passivetype;
1465                         player[i].aitarget=0;
1466                         player[i].madskills=0;
1467
1468                         if(i==0)
1469                         {
1470                                 player[i].proportionhead=1.2;
1471                                 player[i].proportionbody=1.05;
1472                                 player[i].proportionarms=1.00;
1473                                 player[i].proportionlegs=1.1;
1474                                 player[i].proportionlegs.y=1.05;
1475                         }
1476                         player[i].headless=0;
1477                         player[i].currentoffset=0;
1478                         player[i].targetoffset=0;
1479                         /*player[i].armorhead=1;
1480                         player[i].armorhigh=1;
1481                         player[i].armorlow=1;
1482                         player[i].protectionhead=1;
1483                         player[i].protectionhigh=1;
1484                         player[i].protectionlow=1;
1485                         player[i].metalhead=1;
1486                         player[i].metalhigh=1;
1487                         player[i].metallow=1;
1488                         player[i].power=1;
1489                         player[i].speedmult=1;*/
1490
1491                         player[i].damagetolerance=200;
1492
1493                         if(player[i].creature==wolftype)
1494                         {
1495                                 /*player[i].proportionhead=1.1;
1496                                 player[i].proportionbody=1.1;
1497                                 player[i].proportionarms=1.1;
1498                                 player[i].proportionlegs=1.1;
1499                                 player[i].proportionlegs.y=1.1;*/
1500                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1501
1502                                 player[i].damagetolerance=300;
1503                         }
1504
1505                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1506                         if(cellophane)
1507                         {
1508                                 player[i].proportionhead.z=0;
1509                                 player[i].proportionbody.z=0;
1510                                 player[i].proportionarms.z=0;
1511                                 player[i].proportionlegs.z=0;
1512                         }
1513
1514                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1515
1516                         player[i].headmorphness=0;
1517                         player[i].targetheadmorphness=1;
1518                         player[i].headmorphstart=0;
1519                         player[i].headmorphend=0;
1520
1521                         player[i].pausetime=0;
1522
1523                         player[i].dead=0;
1524                         player[i].jumppower=5;
1525                         player[i].damage=0;
1526                         player[i].permanentdamage=0;
1527                         player[i].superpermanentdamage=0;
1528
1529                         player[i].forwardkeydown=0;
1530                         player[i].leftkeydown=0;
1531                         player[i].backkeydown=0;
1532                         player[i].rightkeydown=0;
1533                         player[i].jumpkeydown=0;
1534                         player[i].crouchkeydown=0;
1535                         player[i].throwkeydown=0;
1536
1537                         player[i].collided=-10;
1538                         player[i].loaded=1;
1539                         player[i].bloodloss=0;
1540                         player[i].weaponactive=-1;
1541                         player[i].weaponstuck=-1;
1542                         player[i].bleeding=0;
1543                         player[i].deathbleeding=0;
1544                         player[i].stunned=0;
1545                         player[i].hasvictim=0;
1546                         player[i].wentforweapon=0;
1547                 }
1548
1549                 player[0].aitype=playercontrolled;
1550                 player[0].weaponactive=-1;
1551
1552                 if(difficulty==1)
1553                 {
1554                         //player[0].speedmult=1/.9;
1555                         player[0].power=1/.9;
1556                 }
1557
1558                 if(difficulty==0)
1559                 {
1560                         //player[0].speedmult=1/.8;
1561                         player[0].power=1/.8;
1562                 }
1563
1564                 //player[0].weaponstuck=1;
1565
1566                 if(difficulty==1)player[0].damagetolerance=250;
1567                 if(difficulty==0)player[0].damagetolerance=300;
1568                 if(difficulty==0)player[0].armorhead*=1.5;
1569                 if(difficulty==0)player[0].armorhigh*=1.5;
1570                 if(difficulty==0)player[0].armorlow*=1.5;
1571                 cameraloc=player[0].coords;
1572                 cameraloc.y+=5;
1573                 rotation=player[0].rotation;
1574
1575                 hawkcoords=player[0].coords;
1576                 hawkcoords.y+=30;
1577
1578                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1579                 //weapons.numweapons=numplayers;
1580                 for(i=0;i<weapons.numweapons;i++)
1581                 {
1582                         weapons.bloody[i]=0;
1583                         weapons.blooddrip[i]=0;
1584                         weapons.blooddripdelay[i]=0;
1585                         weapons.onfire[i]=0;
1586                         weapons.flamedelay[i]=0;
1587                         weapons.damage[i]=0;
1588                         //weapons.type[i]=sword;
1589                         if(weapons.type[i]==sword){
1590                                 weapons.mass[i]=1.5;
1591                                 weapons.tipmass[i]=1;
1592                                 weapons.length[i]=.8;
1593                         }
1594                         if(weapons.type[i]==staff){
1595                                 weapons.mass[i]=2;
1596                                 weapons.tipmass[i]=1;
1597                                 weapons.length[i]=1.5;
1598                         }
1599                         if(weapons.type[i]==knife){
1600                                 weapons.mass[i]=1;
1601                                 weapons.tipmass[i]=1.2;
1602                                 weapons.length[i]=.25;
1603                         }
1604                         weapons.position[i]=-1000;
1605                         weapons.tippoint[i]=-1000;
1606                 }
1607
1608 /*              for(i=0;i<32;i++){
1609                         //if(i<16||i>20)
1610                         FSOUND_StopSound(i);
1611                 }
1612 */
1613                 LOG("Starting background music...");
1614
1615                 FSOUND_StopSound(FSOUND_ALL);
1616                 if(environment==snowyenvironment)
1617                 {
1618                         if(ambientsound)
1619                         {
1620                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1621                                 FSOUND_SetPaused(channels[stream_wind], false);
1622                                 FSOUND_SetVolume(channels[stream_wind], 256);
1623                         }
1624                 }
1625                 else if(environment==desertenvironment)
1626                 {
1627                         if(ambientsound)
1628                         {
1629                                 //PlaySoundEx(desertambient,
1630                                 //      samp[desertambient], NULL, true);
1631                                 PlayStreamEx(stream_desertambient,
1632                                         strm[stream_desertambient], NULL, true);
1633                                 FSOUND_SetPaused(channels[stream_desertambient], false);
1634                                 FSOUND_SetVolume(channels[stream_desertambient], 256);
1635                         }
1636                 }
1637                 else if(environment==grassyenvironment)
1638                 {
1639                         if(ambientsound)
1640                         {
1641                                 //PlaySoundEx(wind, samp[wind], NULL, true);
1642                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1643                                 FSOUND_SetPaused(channels[stream_wind], false);
1644                                 FSOUND_SetVolume(channels[stream_wind], 100);
1645                         }
1646                 }
1647                 oldmusicvolume[0]=0;
1648                 oldmusicvolume[1]=0;
1649                 oldmusicvolume[2]=0;
1650                 oldmusicvolume[3]=0;
1651
1652
1653                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1654                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1655                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1656                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1657                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1658                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1659                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1660                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1661                 */
1662
1663                 if(!firstload)
1664                 {
1665                         firstload=1;
1666                 }
1667         }
1668         leveltime=0;
1669         loadingstuff=0;
1670         visibleloading=0;
1671 }
1672
1673 void    Game::Tick()
1674 {
1675         static int i,k,j,l,m;
1676         static XYZ facing,flatfacing,absflatfacing;
1677         static XYZ rotatetarget;
1678         static bool oldkey;
1679         static float oldtargetrotation;
1680         static int target, numgood;
1681         static XYZ tempcoords1,tempcoords2;
1682         static XYZ test;
1683         static XYZ test2;
1684         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1685         static int whichhit;
1686         static bool donesomething;
1687         static bool oldjumpkeydown;
1688
1689         int templength;
1690
1691         float headprop,bodyprop,armprop,legprop;
1692
1693         if(newnetmessages){
1694                 newnetmessages=0;
1695                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1696                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
1697                 FSOUND_SetPaused(channels[consolesuccesssound], false);
1698
1699                 for(k=14;k>=2;k--){
1700                         for(j=0;j<255;j++){
1701                                 consoletext[k][j]=consoletext[k-1][j];
1702                         }
1703                         consolechars[k]=consolechars[k-1];
1704                 }
1705                 for(k=14;k>=2;k--){
1706                         for(j=0;j<255;j++){
1707                                 displaytext[k][j]=displaytext[k-1][j];
1708                         }
1709                         displaychars[k]=displaychars[k-1];
1710                         displaytime[k]=displaytime[k-1];
1711                 }
1712                 for(j=0;j<255;j++){
1713                         consoletext[1][j]=' ';
1714                         displaytext[1][j]=' ';
1715                 }
1716                 sprintf (consoletext[1], netmessages);
1717                 sprintf (displaytext[1], netmessages);
1718                 consolechars[1]=255;
1719                 displaychars[1]=255;
1720                 displaytime[1]=0;
1721         }
1722
1723         for(i=0;i<15;i++){
1724                 displaytime[i]+=multiplier;
1725         }
1726
1727         static unsigned char    theKeyMap[16];
1728         GetKeys( theKeyMap );
1729
1730         keyboardfrozen=0;
1731
1732
1733         static bool mainmenutogglekeydown;
1734         if(!console){
1735                 if(mainmenu&&endgame==1)mainmenu=10;
1736                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1737                         for(j=0;j<255;j++){
1738                                 displaytext[0][j]=' ';
1739                         }
1740                         displaychars[0]=0;
1741                         displayselected=0;
1742                         entername=0;
1743                         mainmenutogglekeydown=1;
1744                 }
1745                 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)){
1746                         selected=-1;
1747                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1748                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1749                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1750                                 else if(mainmenu==0&&winfreeze){
1751                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1752                                         stealthloading=1;
1753                                         else stealthloading=0;
1754
1755                                         if(!stealthloading){
1756                                         float gLoc[3]={0,0,0};
1757                                         float vel[3]={0,0,0};
1758                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1759                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1760                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1761                                         FSOUND_SetVolume(channels[firestartsound], 256);
1762                                         FSOUND_SetPaused(channels[firestartsound], false);
1763                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1764
1765                                         flashr=1;
1766                                         flashg=0;
1767                                         flashb=0;
1768                                         flashamount=1;
1769                                         flashdelay=1;
1770                                         }
1771
1772                                         startbonustotal=0;
1773
1774                                         for(i=0;i<campaignnumlevels;i++){
1775                                         levelvisible[i]=0;
1776                                         levelhighlight[i]=0;
1777                                         }
1778
1779                                         levelorder[0]=0;
1780                                         levelvisible[0]=1;
1781                                         if(accountcampaignchoicesmade[accountactive])
1782                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1783                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1784                                         levelvisible[levelorder[i+1]]=1;
1785                                         }
1786                                         int whichlevelstart;
1787                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1788                                         if(whichlevelstart<0){
1789                                         campaignchoicenum=1;
1790                                         campaignchoicewhich[0]=0;
1791                                         }
1792                                         else
1793                                         {
1794                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1795                                         if(campaignchoicenum)
1796                                         for(i=0;i<campaignchoicenum;i++){
1797                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1798                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1799                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1800                                         }
1801                                         }
1802
1803                                         loading=2;
1804                                         loadtime=0;
1805                                         targetlevel=7;
1806                                         if(firstload)TickOnceAfter();
1807                                         if(!firstload)LoadStuff();
1808                                         //else {
1809                                         for(i=0;i<255;i++){
1810                                         mapname[i]='\0';
1811                                         }
1812                                         mapname[0]=':';
1813                                         mapname[1]='D';
1814                                         mapname[2]='a';
1815                                         mapname[3]='t';
1816                                         mapname[4]='a';
1817                                         mapname[5]=':';
1818                                         mapname[6]='M';
1819                                         mapname[7]='a';
1820                                         mapname[8]='p';
1821                                         mapname[9]='s';
1822                                         mapname[10]=':';
1823
1824                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1825                                         //accountcampaignchoicesmade[accountactive]++;
1826
1827
1828                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1829                                         whichchoice=0;
1830                                         visibleloading=1;
1831                                         stillloading=1;
1832                                         Loadlevel(mapname);
1833                                         campaign=1;
1834                                         mainmenu=0;
1835                                         gameon=1;
1836                                         FSOUND_SetPaused(channels[music3], true);
1837
1838                                         stealthloading=0;*/
1839                                 }
1840                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1841                                 if(mainmenu&&musictoggle){
1842                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1843                                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
1844                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
1845                                                 FSOUND_SetPaused(channels[stream_music3], false);
1846                                                 FSOUND_SetVolume(channels[stream_music3], 256);
1847                                                 FSOUND_SetPaused(channels[music1], true);
1848                                         }
1849                                 }
1850                                 if(!mainmenu){
1851                                         FSOUND_SetPaused(channels[stream_music3], true);
1852                                         FSOUND_SetPaused(channels[music1], false);
1853                                 }
1854                         }
1855                         if(mainmenu==3){
1856                                 float gLoc[3]={0,0,0};
1857                                 float vel[3]={0,0,0};
1858                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1859                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1860                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1861                                 FSOUND_SetVolume(channels[fireendsound], 256);
1862                                 FSOUND_SetPaused(channels[fireendsound], false);
1863                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1864
1865                                 flashr=1;
1866                                 flashg=0;
1867                                 flashb=0;
1868                                 flashamount=1;
1869                                 flashdelay=1;
1870
1871                                 if(newdetail>2)newdetail=detail;
1872                                 if(newdetail<0)newdetail=detail;
1873 #if !USE_SDL  // we'll take anything that works.
1874                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
1875                                 if(newscreenheight>3000)newscreenheight=screenheight;
1876 #endif
1877                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1878                                 if(newscreenheight<0)newscreenheight=screenheight;
1879
1880                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
1881                                 opstream << "Screenwidth:\n";
1882                                 opstream << newscreenwidth;
1883                                 opstream << "\nScreenheight:\n";
1884                                 opstream << newscreenheight;
1885                                 opstream << "\nMouse sensitivity:\n";
1886                                 opstream << usermousesensitivity;
1887                                 opstream << "\nBlur(0,1):\n";
1888                                 opstream << ismotionblur;
1889                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1890                                 opstream << newdetail;
1891                                 opstream << "\nFloating jump:\n";
1892                                 opstream << floatjump;
1893                                 opstream << "\nMouse jump:\n";
1894                                 opstream << mousejump;
1895                                 opstream << "\nAmbient sound:\n";
1896                                 opstream << ambientsound;
1897                                 opstream << "\nBlood (0,1,2):\n";
1898                                 opstream << bloodtoggle;
1899                                 opstream << "\nAuto slomo:\n";
1900                                 opstream << autoslomo;
1901                                 opstream << "\nFoliage:\n";
1902                                 opstream << foliage;
1903                                 opstream << "\nMusic:\n";
1904                                 opstream << musictoggle;
1905                                 opstream << "\nTrilinear:\n";
1906                                 opstream << trilinear;
1907                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1908                                 opstream << decals;
1909                                 opstream << "\nInvert mouse:\n";
1910                                 opstream << invertmouse;
1911                                 opstream << "\nGamespeed:\n";
1912                                 if(oldgamespeed==0)oldgamespeed=1;
1913                                 opstream << oldgamespeed;
1914                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1915                                 opstream << difficulty;
1916                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1917                                 opstream << damageeffects;
1918                                 opstream << "\nText:\n";
1919                                 opstream << texttoggle;
1920                                 opstream << "\nDebug:\n";
1921                                 opstream << debugmode;
1922                                 opstream << "\nVBL Sync:\n";
1923                                 opstream << vblsync;
1924                                 opstream << "\nShow Points:\n";
1925                                 opstream << showpoints;
1926                                 opstream << "\nAlways Blur:\n";
1927                                 opstream << alwaysblur;
1928                                 opstream << "\nImmediate mode (turn on on G5):\n";
1929                                 opstream << immediate;
1930                                 opstream << "\nVelocity blur:\n";
1931                                 opstream << velocityblur;
1932                             opstream << "\nVolume:\n";
1933                         opstream << volume;
1934                                 opstream << "\nForward key:\n";
1935                                 opstream << KeyToChar(forwardkey);
1936                                 opstream << "\nBack key:\n";
1937                                 opstream << KeyToChar(backkey);
1938                                 opstream << "\nLeft key:\n";
1939                                 opstream << KeyToChar(leftkey);
1940                                 opstream << "\nRight key:\n";
1941                                 opstream << KeyToChar(rightkey);
1942                                 opstream << "\nJump key:\n";
1943                                 opstream << KeyToChar(jumpkey);
1944                                 opstream << "\nCrouch key:\n";
1945                                 opstream << KeyToChar(crouchkey);
1946                                 opstream << "\nDraw key:\n";
1947                                 opstream << KeyToChar(drawkey);
1948                                 opstream << "\nThrow key:\n";
1949                                 opstream << KeyToChar(throwkey);
1950                                 opstream << "\nAttack key:\n";
1951                                 opstream << KeyToChar(attackkey);
1952                                 opstream << "\nChat key:\n";
1953                                 opstream << KeyToChar(chatkey);
1954                                 opstream.close();
1955                         }
1956                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==10||mainmenu==11||mainmenu==100){
1957                                 float gLoc[3]={0,0,0};
1958                                 float vel[3]={0,0,0};
1959                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1960                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1961                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1962                                 FSOUND_SetVolume(channels[fireendsound], 256);
1963                                 FSOUND_SetPaused(channels[fireendsound], false);
1964                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1965
1966                                 flashr=1;
1967                                 flashg=0;
1968                                 flashb=0;
1969                                 flashamount=1;
1970                                 flashdelay=1;
1971                         }
1972                         if(mainmenu==3&&gameon)mainmenu=2;
1973                         if(mainmenu==3&&!gameon)mainmenu=1;
1974                         if(mainmenu==5&&gameon)mainmenu=2;
1975                         if(mainmenu==5&&!gameon)mainmenu=1;
1976                         if(mainmenu==4)mainmenu=3;
1977                         if(mainmenu==6)mainmenu=5;
1978                         if(mainmenu==7)mainmenu=1;
1979                         if(mainmenu==9)mainmenu=5;
1980                         if(mainmenu==11)mainmenu=5;
1981                         if(mainmenu==12)mainmenu=5;
1982                         if(mainmenu==13)mainmenu=12;
1983                         if(mainmenu==14)mainmenu=13;
1984                         if(mainmenu==10)mainmenu=5;
1985                         if(mainmenu==100){
1986                                 mainmenu=5;
1987                                 gameon=0;
1988                                 winfreeze=0;
1989                         }
1990                         mainmenutogglekeydown=1;
1991                 }
1992                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1993                         mainmenutogglekeydown=0;
1994                 }
1995         }
1996
1997         /*static bool minimaptogglekeydown;
1998         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1999         minimap=1-minimap;
2000         minimaptogglekeydown=1;
2001         }
2002         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
2003         minimaptogglekeydown=0;
2004         }
2005         */
2006
2007         static bool minimaptogglekeydown;
2008         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
2009                 if(tutorialstage!=51)
2010                         tutorialstagetime=tutorialmaxtime;
2011                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
2012                 FSOUND_SetVolume(channels[consolefailsound], 128);
2013                 FSOUND_SetPaused(channels[consolefailsound], false);
2014                 minimaptogglekeydown=1;
2015         }
2016         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
2017                 minimaptogglekeydown=0;
2018         }
2019
2020         if(mainmenu){
2021                 //menu buttons
2022                 if(mainmenu==1||mainmenu==2){
2023                         if(Button()&&!oldbutton&&selected==1){
2024                                 if(!gameon){
2025                                         float gLoc[3]={0,0,0};
2026                                         float vel[3]={0,0,0};
2027                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2028                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2029                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2030                                         FSOUND_SetVolume(channels[firestartsound], 256);
2031                                         FSOUND_SetPaused(channels[firestartsound], false);
2032                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2033
2034                                         flashr=1;
2035                                         flashg=0;
2036                                         flashb=0;
2037                                         flashamount=1;
2038                                         flashdelay=1;
2039
2040                                         //new game
2041                                         if(accountactive!=-1)mainmenu=5;
2042                                         else mainmenu=7;
2043                                         /*
2044                                         startbonustotal=0;
2045
2046                                         loading=2;
2047                                         loadtime=0;
2048                                         if(firstload)TickOnceAfter();
2049                                         if(!firstload)LoadStuff();
2050                                         else {
2051                                         Loadlevel(0);
2052                                         }
2053                                         mainmenu=0;
2054                                         gameon=1;
2055                                         FSOUND_SetPaused(channels[music3], true);       */
2056                                 }
2057                                 else
2058                                 {
2059                                         //resume
2060                                         mainmenu=0;
2061                                         FSOUND_SetPaused(channels[stream_music3], true);
2062                                         FSOUND_SetPaused(channels[music1], false);
2063                                 }
2064                         }
2065
2066                         if(Button()&&!oldbutton&&selected==2){
2067                                 float gLoc[3]={0,0,0};
2068                                 float vel[3]={0,0,0};
2069                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2070                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2071                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2072                                 FSOUND_SetVolume(channels[firestartsound], 256);
2073                                 FSOUND_SetPaused(channels[firestartsound], false);
2074                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2075
2076                                 flashr=1;
2077                                 flashg=0;
2078                                 flashb=0;
2079                                 flashamount=1;
2080                                 flashdelay=1;
2081
2082                                 //options
2083
2084                                 mainmenu=3;
2085
2086                                 if(newdetail>2)newdetail=detail;
2087                                 if(newdetail<0)newdetail=detail;
2088                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2089                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2090                                 if(newscreenheight>3000)newscreenheight=screenheight;
2091                                 if(newscreenheight<0)newscreenheight=screenheight;
2092                         }
2093
2094                         if(Button()&&!oldbutton&&selected==3){
2095                                 float gLoc[3]={0,0,0};
2096                                 float vel[3]={0,0,0};
2097                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2098                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2099                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2100                                 FSOUND_SetVolume(channels[fireendsound], 256);
2101                                 FSOUND_SetPaused(channels[fireendsound], false);
2102                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2103
2104                                 flashr=1;
2105                                 flashg=0;
2106                                 flashb=0;
2107                                 flashamount=1;
2108                                 flashdelay=1;
2109
2110                                 if(!gameon){
2111                                         //quit
2112                                         tryquit=1;
2113                                         if(registered)FSOUND_SetPaused(channels[stream_music3], true);
2114                                 }
2115                                 else{
2116                                         //end game
2117                                         gameon=0;
2118                                         mainmenu=1;
2119                                 }
2120                         }
2121                         if(Button())oldbutton=1;
2122                         else oldbutton=0;
2123                 }
2124
2125                 if(mainmenu==3){
2126                         if(Button()&&!oldbutton&&selected!=-1){
2127                                 float gLoc[3]={0,0,0};
2128                                 float vel[3]={0,0,0};
2129                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2130                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2131                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2132                                 FSOUND_SetVolume(channels[firestartsound], 256);
2133                                 FSOUND_SetPaused(channels[firestartsound], false);
2134                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2135                         }
2136                         if(Button()&&!oldbutton&&selected==0){
2137                                 #if USE_SDL
2138                                 extern SDL_Rect **resolutions;
2139                                 bool isCustomResolution = true;
2140                                 bool found = false;
2141                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2142                                 {
2143                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2144                                                 isCustomResolution = false;
2145
2146                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2147                                         {
2148                                                 i++;
2149                                                 if (resolutions[i] != NULL)
2150                                                 {
2151                                                         newscreenwidth = (int) resolutions[i]->w;
2152                                                         newscreenheight = (int) resolutions[i]->h;
2153                                                 }
2154                                                 else if (isCustomResolution)
2155                                                 {
2156                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2157                                                         {
2158                                                                 newscreenwidth = (int) resolutions[0]->w;
2159                                                                 newscreenheight = (int) resolutions[0]->h;
2160                                                         }
2161                                                         else
2162                                                         {
2163                                                                 newscreenwidth = screenwidth;
2164                                                                 newscreenheight = screenheight;
2165                                                         }
2166                                                 }
2167                                                 else
2168                                                 {
2169                                                         newscreenwidth = (int) resolutions[0]->w;
2170                                                         newscreenheight = (int) resolutions[0]->h;
2171                                                 }
2172                                                 found = true;
2173                                         }
2174                                 }
2175
2176                                 if (!found)
2177                                 {
2178                                         newscreenwidth = (int) resolutions[0]->w;
2179                                         newscreenheight = (int) resolutions[0]->h;
2180                                 }
2181
2182                                 #else
2183                                 int whichres;
2184                                 whichres=-1;
2185                                 if(newscreenwidth==640&&newscreenheight==480)whichres=0;
2186                                 if(newscreenwidth==800&&newscreenheight==600)whichres=1;
2187                                 if(newscreenwidth==1024&&newscreenheight==768)whichres=2;
2188                                 if(newscreenwidth==1280&&newscreenheight==1024)whichres=3;
2189                                 if(newscreenwidth==1600&&newscreenheight==1200)whichres=4;
2190                                 if(newscreenwidth==840&&newscreenheight==524)whichres=5;
2191                                 if(newscreenwidth==1024&&newscreenheight==640)whichres=6;
2192                                 if(newscreenwidth==1344&&newscreenheight==840)whichres=7;
2193                                 if(newscreenwidth==1920&&newscreenheight==1200)whichres=8;
2194
2195                                 if(whichres==-1||whichres==8){
2196                                         newscreenwidth=640;
2197                                         newscreenheight=480;
2198                                 }
2199                                 if(whichres==0){
2200                                         newscreenwidth=800;
2201                                         newscreenheight=600;
2202                                 }
2203                                 if(whichres==1){
2204                                         newscreenwidth=1024;
2205                                         newscreenheight=768;
2206                                 }
2207                                 if(whichres==2){
2208                                         newscreenwidth=1280;
2209                                         newscreenheight=1024;
2210                                 }
2211                                 if(whichres==3){
2212                                         newscreenwidth=1600;
2213                                         newscreenheight=1200;
2214                                 }
2215                                 if(whichres==4){
2216                                         newscreenwidth=840;
2217                                         newscreenheight=524;
2218                                 }
2219                                 if(whichres==5){
2220                                         newscreenwidth=1024;
2221                                         newscreenheight=640;
2222                                 }
2223                                 if(whichres==6){
2224                                         newscreenwidth=1344;
2225                                         newscreenheight=840;
2226                                 }
2227                                 if(whichres==7){
2228                                         newscreenwidth=1920;
2229                                         newscreenheight=1200;
2230                                 }
2231                                 #endif
2232                         }
2233                         if(Button()&&!oldbutton&&selected==1){
2234                                 newdetail++;
2235                                 if(newdetail>2)newdetail=0;
2236                         }
2237                         if(Button()&&!oldbutton&&selected==2){
2238                                 bloodtoggle++;
2239                                 if(bloodtoggle>2)bloodtoggle=0;
2240                         }
2241                         if(Button()&&!oldbutton&&selected==3){
2242                                 difficulty++;
2243                                 if(difficulty>2)difficulty=0;
2244                         }
2245                         if(Button()&&!oldbutton&&selected==4){
2246                                 ismotionblur=1-ismotionblur;
2247                         }
2248                         if(Button()&&!oldbutton&&selected==5){
2249                                 decals=1-decals;
2250                         }
2251                         if(Button()&&!oldbutton&&selected==6){
2252                                 musictoggle=1-musictoggle;
2253
2254                                 if(!musictoggle){
2255                                         FSOUND_SetPaused(channels[music1], true);
2256                                         FSOUND_SetPaused(channels[stream_music2], true);
2257                                         FSOUND_SetPaused(channels[stream_music3], true);
2258
2259                                         for(i=0;i<4;i++){
2260                                                 oldmusicvolume[i]=0;
2261                                                 musicvolume[i]=0;
2262                                         }
2263                                 }
2264
2265                                 if(musictoggle){
2266                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2267                                         FSOUND_SetPaused(channels[stream_music3], false);
2268                                         FSOUND_SetVolume(channels[stream_music3], 256);
2269                                 }
2270                         }
2271                         if(Button()&&!oldbutton&&selected==9){
2272                                 invertmouse=1-invertmouse;
2273                         }
2274                         if(Button()&&!oldbutton&&selected==10){
2275                                 usermousesensitivity+=.2;
2276                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2277                         }
2278                         if(Button()&&!oldbutton&&selected==11){
2279                                 volume+=.1f;
2280                                 if(volume>1.0001f)volume=0;
2281                                 FSOUND_SetSFXMasterVolume((int)(volume*255));
2282                         }
2283                         if(Button()&&!oldbutton&&selected==7){
2284                                 /*float gLoc[3]={0,0,0};
2285                                 float vel[3]={0,0,0};
2286                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2287                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2288                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2289                                 FSOUND_SetVolume(channels[firestartsound], 256);
2290                                 FSOUND_SetPaused(channels[firestartsound], false);
2291                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2292                                 */
2293                                 flashr=1;
2294                                 flashg=0;
2295                                 flashb=0;
2296                                 flashamount=1;
2297                                 flashdelay=1;
2298
2299                                 //options
2300
2301                                 mainmenu=4;
2302                                 keyselect=-1;
2303                         }
2304                         if(Button()&&!oldbutton&&selected==8){
2305                                 float gLoc[3]={0,0,0};
2306                                 float vel[3]={0,0,0};
2307                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2308                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2309                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2310                                 FSOUND_SetVolume(channels[fireendsound], 256);
2311                                 FSOUND_SetPaused(channels[fireendsound], false);
2312                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2313
2314                                 flashr=1;
2315                                 flashg=0;
2316                                 flashb=0;
2317                                 flashamount=1;
2318                                 flashdelay=1;
2319
2320                                 if(newdetail>2)newdetail=detail;
2321                                 if(newdetail<0)newdetail=detail;
2322 #if !USE_SDL  // we'll take anything that works.
2323                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2324                                 if(newscreenheight>3000)newscreenheight=screenheight;
2325 #endif
2326                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2327                                 if(newscreenheight<0)newscreenheight=screenheight;
2328
2329
2330                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2331                                 opstream << "Screenwidth:\n";
2332                                 opstream << newscreenwidth;
2333                                 opstream << "\nScreenheight:\n";
2334                                 opstream << newscreenheight;
2335                                 opstream << "\nMouse sensitivity:\n";
2336                                 opstream << usermousesensitivity;
2337                                 opstream << "\nBlur(0,1):\n";
2338                                 opstream << ismotionblur;
2339                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2340                                 opstream << newdetail;
2341                                 opstream << "\nFloating jump:\n";
2342                                 opstream << floatjump;
2343                                 opstream << "\nMouse jump:\n";
2344                                 opstream << mousejump;
2345                                 opstream << "\nAmbient sound:\n";
2346                                 opstream << ambientsound;
2347                                 opstream << "\nBlood (0,1,2):\n";
2348                                 opstream << bloodtoggle;
2349                                 opstream << "\nAuto slomo:\n";
2350                                 opstream << autoslomo;
2351                                 opstream << "\nFoliage:\n";
2352                                 opstream << foliage;
2353                                 opstream << "\nMusic:\n";
2354                                 opstream << musictoggle;
2355                                 opstream << "\nTrilinear:\n";
2356                                 opstream << trilinear;
2357                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2358                                 opstream << decals;
2359                                 opstream << "\nInvert mouse:\n";
2360                                 opstream << invertmouse;
2361                                 opstream << "\nGamespeed:\n";
2362                                 if(oldgamespeed==0)oldgamespeed=1;
2363                                 opstream << oldgamespeed;
2364                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2365                                 opstream << difficulty;
2366                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2367                                 opstream << damageeffects;
2368                                 opstream << "\nText:\n";
2369                                 opstream << texttoggle;
2370                                 opstream << "\nDebug:\n";
2371                                 opstream << debugmode;
2372                                 opstream << "\nVBL Sync:\n";
2373                                 opstream << vblsync;
2374                                 opstream << "\nShow Points:\n";
2375                                 opstream << showpoints;
2376                                 opstream << "\nAlways Blur:\n";
2377                                 opstream << alwaysblur;
2378                                 opstream << "\nImmediate mode (turn on on G5):\n";
2379                                 opstream << immediate;
2380                                 opstream << "\nVelocity blur:\n";
2381                                 opstream << velocityblur;
2382                             opstream << "\nVolume:\n";
2383                         opstream << volume;
2384                                 opstream << "\nForward key:\n";
2385                                 opstream << KeyToChar(forwardkey);
2386                                 opstream << "\nBack key:\n";
2387                                 opstream << KeyToChar(backkey);
2388                                 opstream << "\nLeft key:\n";
2389                                 opstream << KeyToChar(leftkey);
2390                                 opstream << "\nRight key:\n";
2391                                 opstream << KeyToChar(rightkey);
2392                                 opstream << "\nJump key:\n";
2393                                 opstream << KeyToChar(jumpkey);
2394                                 opstream << "\nCrouch key:\n";
2395                                 opstream << KeyToChar(crouchkey);
2396                                 opstream << "\nDraw key:\n";
2397                                 opstream << KeyToChar(drawkey);
2398                                 opstream << "\nThrow key:\n";
2399                                 opstream << KeyToChar(throwkey);
2400                                 opstream << "\nAttack key:\n";
2401                                 opstream << KeyToChar(attackkey);
2402                                 opstream << "\nChat key:\n";
2403                                 opstream << KeyToChar(chatkey);
2404                                 opstream.close();
2405
2406                                 if(mainmenu==3&&gameon)mainmenu=2;
2407                                 if(mainmenu==3&&!gameon)mainmenu=1;
2408                         }
2409                         if(Button())oldbutton=1;
2410                         else oldbutton=0;
2411                 }
2412                 if(mainmenu==4){
2413                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2414                                 float gLoc[3]={0,0,0};
2415                                 float vel[3]={0,0,0};
2416                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2417                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2418                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2419                                 FSOUND_SetVolume(channels[firestartsound], 256);
2420                                 FSOUND_SetPaused(channels[firestartsound], false);
2421                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2422                         }
2423                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2424                                 keyselect=selected;
2425                                 oldbuttons[0]=1;
2426                                 oldbuttons[1]=1;
2427                                 oldbuttons[2]=1;
2428                         }
2429                         if(keyselect!=-1){
2430                                 for(i=0;i<3;i++)
2431                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2432                                 for(i=0;i<140;i++){
2433                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2434                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2435                                                         float gLoc[3]={0,0,0};
2436                                                         float vel[3]={0,0,0};
2437                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2438                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2439                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2440                                                         FSOUND_SetVolume(channels[fireendsound], 256);
2441                                                         FSOUND_SetPaused(channels[fireendsound], false);
2442                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2443
2444                                                         int keynum;
2445                                                         keynum=i;
2446                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2447                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2448
2449
2450
2451                                                         if(keyselect==0)forwardkey=keynum;
2452                                                         if(keyselect==1)backkey=keynum;
2453                                                         if(keyselect==2)leftkey=keynum;
2454                                                         if(keyselect==3)rightkey=keynum;
2455                                                         if(keyselect==4)crouchkey=keynum;
2456                                                         if(keyselect==5)jumpkey=keynum;
2457                                                         if(keyselect==6)drawkey=keynum;
2458                                                         if(keyselect==7)throwkey=keynum;
2459                                                         if(keyselect==8)attackkey=keynum;
2460                                                         keyselect=-1;
2461                                                 }
2462                                         }
2463                                 }}
2464                         if(Button()&&!oldbutton&&selected==9){
2465                                 float gLoc[3]={0,0,0};
2466                                 float vel[3]={0,0,0};
2467                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2468                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2469                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2470                                 FSOUND_SetVolume(channels[fireendsound], 256);
2471                                 FSOUND_SetPaused(channels[fireendsound], false);
2472                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2473
2474                                 flashr=1;
2475                                 flashg=0;
2476                                 flashb=0;
2477                                 flashamount=1;
2478                                 flashdelay=1;
2479
2480                                 mainmenu=3;
2481
2482                                 if(newdetail>2)newdetail=detail;
2483                                 if(newdetail<0)newdetail=detail;
2484                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2485                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2486                                 if(newscreenheight>3000)newscreenheight=screenheight;
2487                                 if(newscreenheight<0)newscreenheight=screenheight;
2488                         }
2489                 }
2490
2491                 if(mainmenu==5){
2492                         if(accountcampaignchoicesmade[accountactive]>8&&!registered){
2493                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
2494                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2495                                 FSOUND_SetPaused(channels[stream_music3], false);
2496                                 FSOUND_SetVolume(channels[stream_music3], 256);
2497
2498                                 gameon=0;
2499                                 mainmenu=12;
2500                                 accountcampaignchoicesmade[accountactive]=0;
2501                                 accountcampaignscore[accountactive]=0;
2502                                 accountcampaigntime[accountactive]=0;
2503
2504                                 float gLoc[3]={0,0,0};
2505                                 float vel[3]={0,0,0};
2506                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2507                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2508                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2509                                 FSOUND_SetVolume(channels[fireendsound], 256);
2510                                 FSOUND_SetPaused(channels[fireendsound], false);
2511                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2512
2513                                 flashr=1;
2514                                 flashg=0;
2515                                 flashb=0;
2516                                 flashamount=1;
2517                                 flashdelay=1;
2518                         }
2519
2520                         if(endgame==2){
2521                                 accountcampaignchoicesmade[accountactive]=0;
2522                                 accountcampaignscore[accountactive]=0;
2523                                 accountcampaigntime[accountactive]=0;
2524                                 endgame=0;
2525                         }
2526
2527                         if(Button()&&!oldbutton&&selected==1){
2528                                 float gLoc[3]={0,0,0};
2529                                 float vel[3]={0,0,0};
2530                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2531                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2532                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2533                                 FSOUND_SetVolume(channels[firestartsound], 256);
2534                                 FSOUND_SetPaused(channels[firestartsound], false);
2535                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2536
2537                                 flashr=1;
2538                                 flashg=0;
2539                                 flashb=0;
2540                                 flashamount=1;
2541                                 flashdelay=1;
2542
2543                                 startbonustotal=0;
2544
2545                                 loading=2;
2546                                 loadtime=0;
2547                                 targetlevel=-1;
2548                                 if(firstload)TickOnceAfter();
2549                                 if(!firstload)LoadStuff();
2550                                 else {
2551                                         Loadlevel(-1);
2552                                 }
2553
2554                                 mainmenu=0;
2555                                 gameon=1;
2556                                 FSOUND_SetPaused(channels[stream_music3], true);
2557                         }
2558                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
2559                                 float gLoc[3]={0,0,0};
2560                                 float vel[3]={0,0,0};
2561                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2562                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2563                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2564                                 FSOUND_SetVolume(channels[firestartsound], 256);
2565                                 FSOUND_SetPaused(channels[firestartsound], false);
2566                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2567
2568                                 flashr=1;
2569                                 flashg=0;
2570                                 flashb=0;
2571                                 flashamount=1;
2572                                 flashdelay=1;
2573
2574                                 startbonustotal=0;
2575
2576                                 loading=2;
2577                                 loadtime=0;
2578                                 targetlevel=7;
2579                                 if(firstload)TickOnceAfter();
2580                                 if(!firstload)LoadStuff();
2581                                 //else {
2582                                 for(i=0;i<255;i++){
2583                                         mapname[i]='\0';
2584                                 }
2585                                 mapname[0]=':';
2586                                 mapname[1]='D';
2587                                 mapname[2]='a';
2588                                 mapname[3]='t';
2589                                 mapname[4]='a';
2590                                 mapname[5]=':';
2591                                 mapname[6]='M';
2592                                 mapname[7]='a';
2593                                 mapname[8]='p';
2594                                 mapname[9]='s';
2595                                 mapname[10]=':';
2596                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2597                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2598                                 visibleloading=1;
2599                                 stillloading=1;
2600                                 Loadlevel(mapname);
2601                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2602                                 //}
2603                                 campaign=1;
2604                                 mainmenu=0;
2605                                 gameon=1;
2606                                 FSOUND_SetPaused(channels[stream_music3], true);
2607                         }
2608                         if(Button()&&!oldbutton&&selected==4){
2609                                 float gLoc[3]={0,0,0};
2610                                 float vel[3]={0,0,0};
2611                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2612                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2613                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2614                                 FSOUND_SetVolume(channels[fireendsound], 256);
2615                                 FSOUND_SetPaused(channels[fireendsound], false);
2616                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2617
2618                                 flashr=1;
2619                                 flashg=0;
2620                                 flashb=0;
2621                                 flashamount=1;
2622                                 flashdelay=1;
2623
2624                                 if(mainmenu==5&&gameon)mainmenu=2;
2625                                 if(mainmenu==5&&!gameon)mainmenu=1;
2626                         }
2627                         if(Button()&&!oldbutton&&selected==5){
2628                                 float gLoc[3]={0,0,0};
2629                                 float vel[3]={0,0,0};
2630                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2631                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2632                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2633                                 FSOUND_SetVolume(channels[fireendsound], 256);
2634                                 FSOUND_SetPaused(channels[fireendsound], false);
2635                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2636
2637                                 flashr=1;
2638                                 flashg=0;
2639                                 flashb=0;
2640                                 flashamount=1;
2641                                 flashdelay=1;
2642
2643                                 mainmenu=7;
2644                         }
2645                         if(Button()&&!oldbutton&&selected==3){
2646                                 float gLoc[3]={0,0,0};
2647                                 float vel[3]={0,0,0};
2648                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2649                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2650                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2651                                 FSOUND_SetVolume(channels[firestartsound], 256);
2652                                 FSOUND_SetPaused(channels[firestartsound], false);
2653                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2654
2655                                 flashr=1;
2656                                 flashg=0;
2657                                 flashb=0;
2658                                 flashamount=1;
2659                                 flashdelay=1;
2660
2661                                 mainmenu=6;
2662                         }
2663                         if(Button()&&!oldbutton&&selected==2){
2664                                 float gLoc[3]={0,0,0};
2665                                 float vel[3]={0,0,0};
2666                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2667                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2668                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2669                                 FSOUND_SetVolume(channels[firestartsound], 256);
2670                                 FSOUND_SetPaused(channels[firestartsound], false);
2671                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2672
2673                                 flashr=1;
2674                                 flashg=0;
2675                                 flashb=0;
2676                                 flashamount=1;
2677                                 flashdelay=1;
2678
2679                                 mainmenu=9;
2680                         }
2681                         if(Button())oldbutton=1;
2682                         else oldbutton=0;
2683                 }
2684                 if(mainmenu==9){
2685                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2686                                 float gLoc[3]={0,0,0};
2687                                 float vel[3]={0,0,0};
2688                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2689                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2690                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2691                                 FSOUND_SetVolume(channels[firestartsound], 256);
2692                                 FSOUND_SetPaused(channels[firestartsound], false);
2693                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2694
2695                                 flashr=1;
2696                                 flashg=0;
2697                                 flashb=0;
2698                                 flashamount=1;
2699                                 flashdelay=1;
2700
2701                                 startbonustotal=0;
2702
2703                                 loading=2;
2704                                 loadtime=0;
2705                                 targetlevel=selected;
2706                                 if(firstload)TickOnceAfter();
2707                                 if(!firstload)LoadStuff();
2708                                 else {
2709                                         Loadlevel(selected);
2710                                 }
2711                                 campaign=0;
2712
2713                                 mainmenu=0;
2714                                 gameon=1;
2715                                 FSOUND_SetPaused(channels[stream_music3], true);
2716                         }
2717                         if(Button()&&!oldbutton&&selected==numchallengelevels){
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                 if(mainmenu==11){
2739                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2740                                 float gLoc[3]={0,0,0};
2741                                 float vel[3]={0,0,0};
2742                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2743                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2744                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2745                                 FSOUND_SetVolume(channels[firestartsound], 256);
2746                                 FSOUND_SetPaused(channels[firestartsound], false);
2747                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2748
2749                                 flashr=1;
2750                                 flashg=0;
2751                                 flashb=0;
2752                                 flashamount=1;
2753                                 flashdelay=1;
2754
2755                                 startbonustotal=0;
2756
2757                                 loading=2;
2758                                 loadtime=0;
2759                                 targetlevel=selected;
2760                                 if(firstload)TickOnceAfter();
2761                                 if(!firstload)LoadStuff();
2762                                 else {
2763                                         Loadlevel(selected);
2764                                 }
2765                                 campaign=0;
2766
2767                                 mainmenu=0;
2768                                 gameon=1;
2769                                 FSOUND_SetPaused(channels[stream_music3], true);
2770                         }
2771                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2772                                 float gLoc[3]={0,0,0};
2773                                 float vel[3]={0,0,0};
2774                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2775                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2776                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2777                                 FSOUND_SetVolume(channels[fireendsound], 256);
2778                                 FSOUND_SetPaused(channels[fireendsound], false);
2779                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2780
2781                                 flashr=1;
2782                                 flashg=0;
2783                                 flashb=0;
2784                                 flashamount=1;
2785                                 flashdelay=1;
2786
2787                                 mainmenu=5;
2788                         }
2789                         if(Button())oldbutton=1;
2790                         else oldbutton=0;
2791                 }
2792                 if(mainmenu==10){
2793                         endgame=2;
2794                         if(Button()&&!oldbutton&&selected==3){
2795                                 float gLoc[3]={0,0,0};
2796                                 float vel[3]={0,0,0};
2797                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2798                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2799                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2800                                 FSOUND_SetVolume(channels[fireendsound], 256);
2801                                 FSOUND_SetPaused(channels[fireendsound], false);
2802                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2803
2804                                 flashr=1;
2805                                 flashg=0;
2806                                 flashb=0;
2807                                 flashamount=1;
2808                                 flashdelay=1;
2809
2810                                 mainmenu=5;
2811                         }
2812                         if(Button())oldbutton=1;
2813                         else oldbutton=0;
2814                 }
2815
2816                 if(mainmenu==15||mainmenu==16){
2817                         if(Button()&&!oldbutton&&selected==1){
2818                                 float gLoc[3]={0,0,0};
2819                                 float vel[3]={0,0,0};
2820                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2821                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2822                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2823                                 FSOUND_SetVolume(channels[fireendsound], 256);
2824                                 FSOUND_SetPaused(channels[fireendsound], false);
2825                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2826
2827                                 flashr=1;
2828                                 flashg=0;
2829                                 flashb=0;
2830                                 flashamount=1;
2831                                 flashdelay=1;
2832
2833                                 if(mainmenu==15)mainmenu=5;
2834                                 else mainmenu=12;
2835                         }
2836                         if(Button())oldbutton=1;
2837                         else oldbutton=0;
2838                 }
2839
2840                 if(mainmenu==12){
2841                         endgame=2;
2842                         if(Button()&&!oldbutton&&selected==3){
2843                                 if(tryquit)quit=1;
2844                                 float gLoc[3]={0,0,0};
2845                                 float vel[3]={0,0,0};
2846                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2847                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2848                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2849                                 FSOUND_SetVolume(channels[fireendsound], 256);
2850                                 FSOUND_SetPaused(channels[fireendsound], false);
2851                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2852
2853                                 flashr=1;
2854                                 flashg=0;
2855                                 flashb=0;
2856                                 flashamount=1;
2857                                 flashdelay=1;
2858
2859                                 mainmenu=5;
2860                         }
2861
2862                         if(Button()&&!oldbutton&&selected==4){
2863                                 registernow=1;
2864                                 quit=1;
2865                                 float gLoc[3]={0,0,0};
2866                                 float vel[3]={0,0,0};
2867                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2868                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2869                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2870                                 FSOUND_SetVolume(channels[fireendsound], 256);
2871                                 FSOUND_SetPaused(channels[fireendsound], false);
2872                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2873
2874                                 flashr=1;
2875                                 flashg=0;
2876                                 flashb=0;
2877                                 flashamount=1;
2878                                 flashdelay=1;
2879                         }
2880
2881
2882                         if(Button()&&!oldbutton&&selected==5){
2883                                 tryquit=0;
2884                                 float gLoc[3]={0,0,0};
2885                                 float vel[3]={0,0,0};
2886                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2887                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2888                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2889                                 FSOUND_SetVolume(channels[fireendsound], 256);
2890                                 FSOUND_SetPaused(channels[fireendsound], false);
2891                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2892
2893                                 flashr=1;
2894                                 flashg=0;
2895                                 flashb=0;
2896                                 flashamount=1;
2897                                 flashdelay=1;
2898
2899                                 mainmenu=13;
2900                         }
2901                         if(Button())oldbutton=1;
2902                         else oldbutton=0;
2903                 }
2904                 if(mainmenu==6){
2905                         if(Button()&&!oldbutton&&selected!=-1){
2906                                 float gLoc[3]={0,0,0};
2907                                 float vel[3]={0,0,0};
2908                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2909                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2910                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2911                                 FSOUND_SetVolume(channels[firestartsound], 256);
2912                                 FSOUND_SetPaused(channels[firestartsound], false);
2913                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2914                         }
2915                         if(Button()&&!oldbutton&&selected==1){
2916                                 float gLoc[3]={0,0,0};
2917                                 float vel[3]={0,0,0};
2918                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2919                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2920                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2921                                 FSOUND_SetVolume(channels[fireendsound], 256);
2922                                 FSOUND_SetPaused(channels[fireendsound], false);
2923                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2924
2925                                 flashr=1;
2926                                 flashg=0;
2927                                 flashb=0;
2928                                 flashamount=1;
2929                                 flashdelay=1;
2930
2931                                 for(i=accountactive;i<numaccounts-1;i++){
2932                                         accountdifficulty[i]=accountdifficulty[i+1];
2933                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2934                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2935                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2936                                         }
2937                                         accountpoints[i]=accountpoints[i+1];
2938                                         for(j=0;j<50;j++){
2939                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2940                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2941                                         }
2942                                         for(j=0;j<60;j++){
2943                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2944                                         }
2945                                         for(j=0;j<256;j++){
2946                                                 accountname[i][j]=accountname[i+1][j];
2947                                         }
2948                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2949                                         accountprogress[i]=accountprogress[i+1];
2950                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2951                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2952                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2953                                 }
2954
2955                                 numaccounts--;
2956                                 accountactive=-1;
2957
2958
2959                                 mainmenu=7;
2960                         }
2961                         if(Button()&&!oldbutton&&selected==2){
2962                                 float gLoc[3]={0,0,0};
2963                                 float vel[3]={0,0,0};
2964                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2965                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2966                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2967                                 FSOUND_SetVolume(channels[fireendsound], 256);
2968                                 FSOUND_SetPaused(channels[fireendsound], false);
2969                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2970
2971                                 flashr=1;
2972                                 flashg=0;
2973                                 flashb=0;
2974                                 flashamount=1;
2975                                 flashdelay=1;
2976
2977                                 mainmenu=5;
2978                         }
2979                         if(Button())oldbutton=1;
2980                         else oldbutton=0;
2981                 }
2982                 if(mainmenu==7){
2983                         if(Button()&&!oldbutton&&selected!=-1){
2984                                 float gLoc[3]={0,0,0};
2985                                 float vel[3]={0,0,0};
2986                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2987                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2988                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2989                                 FSOUND_SetVolume(channels[firestartsound], 256);
2990                                 FSOUND_SetPaused(channels[firestartsound], false);
2991                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2992                         }
2993                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2994                                 entername=1;
2995                         }
2996                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2997                                 accountactive=selected-1;
2998                                 mainmenu=5;
2999                                 flashr=1;
3000                                 flashg=0;
3001                                 flashb=0;
3002                                 flashamount=1;
3003                                 flashdelay=1;
3004                         }
3005                         if(Button()&&!oldbutton&&selected==numaccounts+1){
3006                                 float gLoc[3]={0,0,0};
3007                                 float vel[3]={0,0,0};
3008                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
3009                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
3010                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
3011                                 FSOUND_SetVolume(channels[fireendsound], 256);
3012                                 FSOUND_SetPaused(channels[fireendsound], false);
3013                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
3014
3015                                 flashr=1;
3016                                 flashg=0;
3017                                 flashb=0;
3018                                 flashamount=1;
3019                                 flashdelay=1;
3020
3021                                 mainmenu=1;
3022
3023                                 for(j=0;j<255;j++){
3024                                         displaytext[0][j]=' ';
3025                                 }
3026                                 displaychars[0]=0;
3027                                 displayselected=0;
3028                                 entername=0;
3029                         }
3030                         if(Button())oldbutton=1;
3031                         else oldbutton=0;
3032                 }
3033                 if(mainmenu==8){
3034                         if(Button()&&!oldbutton&&selected!=-1){
3035                                 float gLoc[3]={0,0,0};
3036                                 float vel[3]={0,0,0};
3037                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3038                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3039                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3040                                 FSOUND_SetVolume(channels[firestartsound], 256);
3041                                 FSOUND_SetPaused(channels[firestartsound], false);
3042                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3043
3044                                 if(selected==0)accountdifficulty[accountactive]=0;
3045                                 if(selected==1)accountdifficulty[accountactive]=1;
3046                                 if(selected==2)accountdifficulty[accountactive]=2;
3047
3048                                 mainmenu=5;
3049
3050                                 flashr=1;
3051                                 flashg=0;
3052                                 flashb=0;
3053                                 flashamount=1;
3054                                 flashdelay=1;
3055
3056                         }
3057                         if(Button())oldbutton=1;
3058                         else oldbutton=0;
3059                 }
3060
3061
3062                 if(Button())oldbutton=1;
3063                 else oldbutton=0;
3064
3065                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
3066                         tryquit=1;
3067                         if(mainmenu==3){
3068                                 if(newdetail>2)newdetail=detail;
3069                                 if(newdetail<0)newdetail=detail;
3070 #if !USE_SDL  // we'll take anything that works.
3071                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
3072                                 if(newscreenheight>3000)newscreenheight=screenheight;
3073 #endif
3074                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
3075                                 if(newscreenheight<0)newscreenheight=screenheight;
3076
3077                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
3078                                 opstream << "Screenwidth:\n";
3079                                 opstream << newscreenwidth;
3080                                 opstream << "\nScreenheight:\n";
3081                                 opstream << newscreenheight;
3082                                 opstream << "\nMouse sensitivity:\n";
3083                                 opstream << usermousesensitivity;
3084                                 opstream << "\nBlur(0,1):\n";
3085                                 opstream << ismotionblur;
3086                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
3087                                 opstream << newdetail;
3088                                 opstream << "\nFloating jump:\n";
3089                                 opstream << floatjump;
3090                                 opstream << "\nMouse jump:\n";
3091                                 opstream << mousejump;
3092                                 opstream << "\nAmbient sound:\n";
3093                                 opstream << ambientsound;
3094                                 opstream << "\nBlood (0,1,2):\n";
3095                                 opstream << bloodtoggle;
3096                                 opstream << "\nAuto slomo:\n";
3097                                 opstream << autoslomo;
3098                                 opstream << "\nFoliage:\n";
3099                                 opstream << foliage;
3100                                 opstream << "\nMusic:\n";
3101                                 opstream << musictoggle;
3102                                 opstream << "\nTrilinear:\n";
3103                                 opstream << trilinear;
3104                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
3105                                 opstream << decals;
3106                                 opstream << "\nInvert mouse:\n";
3107                                 opstream << invertmouse;
3108                                 opstream << "\nGamespeed:\n";
3109                                 if(oldgamespeed==0)oldgamespeed=1;
3110                                 opstream << oldgamespeed;
3111                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
3112                                 opstream << difficulty;
3113                                 opstream << "\nDamage effects(blackout, doublevision):\n";
3114                                 opstream << damageeffects;
3115                                 opstream << "\nText:\n";
3116                                 opstream << texttoggle;
3117                                 opstream << "\nDebug:\n";
3118                                 opstream << debugmode;
3119                                 opstream << "\nVBL Sync:\n";
3120                                 opstream << vblsync;
3121                                 opstream << "\nShow Points:\n";
3122                                 opstream << showpoints;
3123                                 opstream << "\nAlways Blur:\n";
3124                                 opstream << alwaysblur;
3125                                 opstream << "\nImmediate mode (turn on on G5):\n";
3126                                 opstream << immediate;
3127                                 opstream << "\nVelocity blur:\n";
3128                                 opstream << velocityblur;
3129                             opstream << "\nVolume:\n";
3130                         opstream << volume;
3131                                 opstream << "\nForward key:\n";
3132                                 opstream << KeyToChar(forwardkey);
3133                                 opstream << "\nBack key:\n";
3134                                 opstream << KeyToChar(backkey);
3135                                 opstream << "\nLeft key:\n";
3136                                 opstream << KeyToChar(leftkey);
3137                                 opstream << "\nRight key:\n";
3138                                 opstream << KeyToChar(rightkey);
3139                                 opstream << "\nJump key:\n";
3140                                 opstream << KeyToChar(jumpkey);
3141                                 opstream << "\nCrouch key:\n";
3142                                 opstream << KeyToChar(crouchkey);
3143                                 opstream << "\nDraw key:\n";
3144                                 opstream << KeyToChar(drawkey);
3145                                 opstream << "\nThrow key:\n";
3146                                 opstream << KeyToChar(throwkey);
3147                                 opstream << "\nAttack key:\n";
3148                                 opstream << KeyToChar(attackkey);
3149                                 opstream << "\nChat key:\n";
3150                                 opstream << KeyToChar(chatkey);
3151                                 opstream.close();
3152                         }
3153                 }
3154
3155                 if(mainmenu==1||mainmenu==2){
3156                         if(loaddistrib>4)transition+=multiplier/8;
3157                         if(transition>1){
3158                                 transition=0;
3159                                 anim++;
3160                                 if(anim>4)anim=0;
3161                                 loaddistrib=0;
3162                         }
3163                 }
3164                 FSOUND_SetFrequency(channels[stream_music3], 22050);
3165
3166                 if(entername||mainmenu==13||mainmenu==14){
3167                         for(i=0;i<140;i++){
3168                                 if(IsKeyDown(theKeyMap, i)){
3169                                         togglekeydelay[i]+=multiplier;
3170                                         if(togglekeydelay[i]>.4){
3171                                                 togglekey[i]=0;
3172                                                 togglekeydelay[i]=.36;
3173                                         }
3174                                         if(!togglekey[i]){
3175                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3176                                                         for(j=255;j>=displayselected+1;j--){
3177                                                                 displaytext[0][j]=displaytext[0][j-1];
3178                                                         }
3179                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3180                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3181                                                         displayselected++;
3182                                                         displaychars[0]++;
3183                                                 }
3184                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3185                                                         for(j=displayselected-1;j<255;j++){
3186                                                                 displaytext[0][j]=displaytext[0][j+1];
3187                                                         }
3188                                                         displaytext[0][255]=' ';
3189                                                         displayselected--;
3190                                                         displaychars[0]--;
3191                                                 }
3192                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3193                                                         displayselected--;
3194                                                 }
3195                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3196                                                         displayselected++;
3197                                                 }
3198                                                 if(i==MAC_RETURN_KEY&&entername){
3199                                                         if(displaychars[0]){
3200                                                                 numaccounts++;
3201                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
3202                                                                 accountactive=numaccounts-1;
3203                                                                 accountdifficulty[accountactive]=1;
3204                                                                 accountprogress[accountactive]=0;
3205                                                                 accountpoints[accountactive]=0;
3206                                                                 accountcampaigntime[accountactive]=0;
3207                                                                 accountcampaignscore[accountactive]=0;
3208                                                                 accountcampaignfasttime[accountactive]=0;
3209                                                                 accountcampaignhighscore[accountactive]=0;
3210                                                                 for(j=0;j<50;j++){
3211                                                                         accounthighscore[accountactive][j]=0;
3212                                                                         accountfasttime[accountactive][j]=0;
3213                                                                 }
3214                                                                 for(j=0;j<60;j++){
3215                                                                         accountunlocked[accountactive][j]=0;
3216                                                                 }
3217                                                                 accountcampaignchoicesmade[accountactive]=0;
3218
3219                                                                 for(j=0;j<255;j++){
3220                                                                         displaytext[0][j]=' ';
3221                                                                 }
3222                                                                 displaychars[0]=0;
3223                                                                 displayselected=0;
3224                                                                 entername=0;
3225
3226                                                                 mainmenu=8;
3227
3228                                                                 flashr=1;
3229                                                                 flashg=0;
3230                                                                 flashb=0;
3231                                                                 flashamount=1;
3232                                                                 flashdelay=1;
3233
3234                                                                 float gLoc[3]={0,0,0};
3235                                                                 float vel[3]={0,0,0};
3236                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3237                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3238                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3239                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3240                                                                 FSOUND_SetPaused(channels[firestartsound], false);
3241                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3242
3243                                                                 for(j=0;j<255;j++){
3244                                                                         displaytext[0][j]=' ';
3245                                                                 }
3246                                                                 displaychars[0]=0;
3247
3248
3249                                                                 displayselected=0;
3250                                                         }}
3251
3252                                                 if(i==MAC_RETURN_KEY&&mainmenu==14){
3253                                                         if(displaychars[0]){
3254                                                                 char serialstring[256];
3255                                                                 char tempstring[256];
3256                                                                 #if defined(__APPLE__)
3257                                                                 sprintf (tempstring, "%s", registrationname);
3258                                                                 #elif defined(_WIN32) || defined(__linux__)
3259                                                                 sprintf (tempstring, "%s-windows", registrationname);
3260                                                                 #else
3261                                                                 #error Please make sure you have the right registration key stuff here!
3262                                                                 #endif
3263                                                                 long num1;
3264                                                                 long num2;
3265                                                                 long num3;
3266                                                                 long num4;
3267                                                                 long long longnum;
3268                                                                 longnum = MD5_string ( tempstring);
3269                                                                 //longnum = 1111111111111111;
3270                                                                 num1 = longnum/100000000;
3271                                                                 num2 = longnum%100000000;
3272                                                                 sprintf (tempstring, "%d-%d-%d-%d\0\0\0\0\0", num1/10000, num1%10000, num2/10000, num2%10000);
3273
3274                                                                 int goodcode=3;
3275                                                                 int numchars=3;
3276                                                                 if(num1/10000>999)numchars+=4;
3277                                                                 else if(num1/10000>99)numchars+=3;
3278                                                                 else if(num1/10000>9)numchars+=2;
3279                                                                 else numchars+=1;
3280                                                                 if(num1%10000>999)numchars+=4;
3281                                                                 else if(num1%10000>99)numchars+=3;
3282                                                                 else if(num1%10000>9)numchars+=2;
3283                                                                 else numchars+=1;
3284                                                                 if(num2/10000>999)numchars+=4;
3285                                                                 else if(num2/10000>99)numchars+=3;
3286                                                                 else if(num2/10000>9)numchars+=2;
3287                                                                 else numchars+=1;
3288                                                                 if(num2%10000>999)numchars+=4;
3289                                                                 else if(num2%10000>99)numchars+=3;
3290                                                                 else if(num2%10000>9)numchars+=2;
3291                                                                 else numchars+=1;
3292
3293                                                                 //numchars=12;
3294
3295                                                                 for(j=0;j<numchars;j++){
3296                                                                         if(displaytext[0][j]!=tempstring[j]&&tempstring[j]!=' '&&tempstring[j]!='\0')goodcode--;
3297                                                                 }
3298
3299                                                                 if(longnum==LONGLONGCONST(5077041556214789))goodcode=-1;
3300
3301                                                                 if(goodcode<0)goodcode=0;
3302
3303                                                                 if(goodcode){
3304                                                                         registered=1;
3305                                                                         mainmenu=15;
3306
3307                                                                         FILE                    *tfile;
3308                                                                         tfile=fopen( ":Data:Sounds:flame.ogg", "wb" );
3309                                                                         if (tfile)
3310                                                                         {
3311                                                                                 int numchars;
3312                                                                                 numchars=strlen(registrationname);
3313                                                                                 fpackf(tfile, "Bb", registered);
3314                                                                                 fpackf(tfile, "Bi", numchars);
3315                                                                                 if(numchars>0)
3316                                                                                 {
3317                                                                                         for(j=0;j<numchars;j++)
3318                                                                                         {
3319                                                                                                 fpackf(tfile, "Bb",  registrationname[j]);
3320                                                                                         }
3321                                                                                 }
3322                                                                                 fpackf(tfile, "Bi", num1);
3323                                                                                 fpackf(tfile, "Bi", num2);
3324                                                                                 fclose(tfile);
3325                                                                         }
3326                                                                 }
3327                                                                 else
3328                                                                 {
3329                                                                         mainmenu=16;
3330                                                                 }
3331                                                                 flashr=1;
3332                                                                 flashg=0;
3333                                                                 flashb=0;
3334                                                                 flashamount=1;
3335                                                                 flashdelay=1;
3336
3337                                                                 float gLoc[3]={0,0,0};
3338                                                                 float vel[3]={0,0,0};
3339                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3340                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3341                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3342                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3343                                                                 FSOUND_SetPaused(channels[firestartsound], false);
3344                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3345
3346                                                                 for(j=0;j<255;j++){
3347                                                                         displaytext[0][j]=' ';
3348                                                                 }
3349                                                                 displaychars[0]=0;
3350                                                                 displayselected=0;
3351                                                         }}
3352
3353                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3354                                                         if(displaychars[0]){
3355                                                                 sprintf (registrationname, "%s", displaytext[0]);
3356                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3357
3358                                                                 mainmenu=14;
3359
3360                                                                 flashr=1;
3361                                                                 flashg=0;
3362                                                                 flashb=0;
3363                                                                 flashamount=1;
3364                                                                 flashdelay=1;
3365
3366                                                                 float gLoc[3]={0,0,0};
3367                                                                 float vel[3]={0,0,0};
3368                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3369                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3370                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3371                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3372                                                                 FSOUND_SetPaused(channels[firestartsound], false);
3373                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3374
3375                                                                 for(j=0;j<255;j++){
3376                                                                         displaytext[0][j]=' ';
3377                                                                 }
3378                                                                 displaychars[0]=0;
3379
3380                                                                 /*char tempstring[50];
3381                                                                 sprintf (tempstring, registrationname);
3382                                                                 long num1;
3383                                                                 long num2;
3384                                                                 long num3;
3385                                                                 long num4;
3386                                                                 long long longnum;
3387                                                                 longnum = MD5_string ( tempstring);
3388                                                                 num1 = longnum/100000000;
3389                                                                 num2 = longnum%100000000;
3390                                                                 sprintf (displaytext[0], "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
3391
3392                                                                 displaychars[0]=strlen(displaytext[0]);
3393                                                                 */
3394                                                                 displayselected=0;
3395                                                         }}
3396                                         }
3397                                         togglekey[i]=1;
3398                                 }
3399                                 else {
3400                                         togglekey[i]=0;
3401                                         togglekeydelay[i]=0;
3402                                 }
3403                         }
3404
3405                         displayblinkdelay-=multiplier;
3406                         if(displayblinkdelay<=0){
3407                                 displayblinkdelay=.3;
3408                                 displayblink=1-displayblink;
3409                         }
3410                 }
3411         }
3412
3413         if(!mainmenu){
3414                 if(hostile==1)hostiletime+=multiplier;
3415                 else hostiletime=0;
3416                 if(!winfreeze)leveltime+=multiplier;
3417                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3418                         chatting=0;
3419                         console=0;
3420                         freeze=0;
3421                         displaychars[0]=0;
3422                 }
3423
3424                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3425                         chatting=1;
3426                         chattogglekeydown=1;
3427                         togglekey[chatkey]=1;
3428                         togglekeydelay[chatkey]=-20;
3429                 }
3430
3431                 if(!IsKeyDown(theKeyMap, chatkey)){
3432                         chattogglekeydown=0;
3433                 }
3434
3435                 if(chatting){
3436                         for(i=0;i<140;i++){
3437                                 if(IsKeyDown(theKeyMap, i)){
3438                                         togglekeydelay[i]+=multiplier;
3439                                         if(togglekeydelay[i]>.4){
3440                                                 togglekey[i]=0;
3441                                                 togglekeydelay[i]=.36;
3442                                         }
3443                                         if(!togglekey[i]){
3444                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3445                                                         for(j=255;j>=displayselected+1;j--){
3446                                                                 displaytext[0][j]=displaytext[0][j-1];
3447                                                         }
3448                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3449                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3450                                                         displayselected++;
3451                                                         displaychars[0]++;
3452                                                 }
3453                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3454                                                         for(j=displayselected-1;j<255;j++){
3455                                                                 displaytext[0][j]=displaytext[0][j+1];
3456                                                         }
3457                                                         displaytext[0][255]=' ';
3458                                                         displayselected--;
3459                                                         displaychars[0]--;
3460                                                 }
3461                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3462                                                         displayselected--;
3463                                                 }
3464                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3465                                                         displayselected++;
3466                                                 }
3467                                                 if(i==MAC_RETURN_KEY){
3468                                                         if(displaychars[0]){
3469                                                                 /*for(j=0;j<displaychars[0];j++){
3470                                                                 talkname[j]=displaytext[0][j];
3471                                                                 }
3472                                                                 talkname[displaychars[0]]='\0';
3473                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3474                                                                 //NetworkSendInformation(chatname);
3475                                                                 */
3476                                                                 for(j=0;j<255;j++){
3477                                                                         displaytext[0][j]=' ';
3478                                                                 }
3479                                                                 displaychars[0]=0;
3480                                                                 displayselected=0;
3481                                                                 chatting=0;
3482                                                         }
3483                                                 }
3484                                         }
3485                                         togglekey[i]=1;
3486                                 }
3487                                 else {
3488                                         togglekey[i]=0;
3489                                         togglekeydelay[i]=0;
3490                                 }
3491                         }
3492
3493                         displayblinkdelay-=multiplier;
3494                         if(displayblinkdelay<=0){
3495                                 displayblinkdelay=.3;
3496                                 displayblink=1-displayblink;
3497                         }
3498                 }
3499
3500                 if(chatting)keyboardfrozen=1;
3501
3502                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3503                         freeze=1-freeze;
3504                         if(freeze){
3505                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3506                         }
3507                         freezetogglekeydown=1;
3508                 }
3509
3510                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3511                         freezetogglekeydown=0;
3512                 }
3513
3514                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3515                         console=1-console;
3516                         if(!console)freeze=0;
3517                         if(console){
3518                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3519                         }
3520                         consoletogglekeydown=1;
3521                 }
3522
3523                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3524                         consoletogglekeydown=0;
3525                 }
3526
3527                 if(console)freeze=1;
3528
3529                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3530                         for(i=0;i<140;i++){
3531                                 if(IsKeyDown(theKeyMap, i)){
3532                                         togglekeydelay[i]+=multiplier;
3533                                         if(togglekeydelay[i]>.4){
3534                                                 togglekey[i]=0;
3535                                                 togglekeydelay[i]=.36;
3536                                         }
3537                                         if(!togglekey[i]){
3538                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3539                                                         for(j=255;j>=consoleselected+1;j--){
3540                                                                 consoletext[0][j]=consoletext[0][j-1];
3541                                                         }
3542                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3543                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3544                                                         consoleselected++;
3545                                                         consolechars[0]++;
3546                                                 }
3547                                                 else if(i==MAC_ENTER_KEY){
3548                                                         for(j=255;j>=consoleselected+1;j--){
3549                                                                 consoletext[0][j]=consoletext[0][j-1];
3550                                                         }
3551                                                         consoletext[0][consoleselected]='\n';
3552                                                         consoleselected++;
3553                                                         consolechars[0]++;
3554                                                 }
3555                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3556                                                         for(j=consoleselected-1;j<255;j++){
3557                                                                 consoletext[0][j]=consoletext[0][j+1];
3558                                                         }
3559                                                         consoletext[0][255]=' ';
3560                                                         consoleselected--;
3561                                                         consolechars[0]--;
3562                                                 }
3563                                                 if(i==MAC_ARROW_UP_KEY){
3564                                                         if(archiveselected<14)archiveselected++;
3565                                                         for(j=0;j<255;j++){
3566                                                                 consolechars[0]=consolechars[archiveselected];
3567                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3568                                                                 consoleselected=consolechars[0];
3569                                                         }
3570                                                 }
3571                                                 if(i==MAC_ARROW_DOWN_KEY){
3572                                                         if(archiveselected>0)archiveselected--;
3573                                                         for(j=0;j<255;j++){
3574                                                                 consolechars[0]=consolechars[archiveselected];
3575                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3576                                                                 consoleselected=consolechars[0];
3577                                                         }
3578                                                 }
3579                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3580                                                         consoleselected--;
3581                                                 }
3582                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3583                                                         consoleselected++;
3584                                                 }
3585                                                 if(i==MAC_RETURN_KEY){
3586                                                         archiveselected=0;
3587                                                         donesomething=0;
3588                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3589                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3590                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3591                                                                 FSOUND_SetPaused(channels[consolesuccesssound], false);
3592                                                                 donesomething=1;
3593                                                                 tryquit=1;
3594                                                         }
3595                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3596                                                         for(j=5;j<consolechars[0];j++){
3597                                                         talkname[j-5]=consoletext[0][j];
3598                                                         }
3599                                                         talkname[consolechars[0]-5]='\0';
3600                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3601                                                         //NetworkSendInformation(chatname);
3602                                                         donesomething=1;
3603                                                         }
3604                                                         if(Compare(consoletext[0],"name ",0,4)){
3605                                                         int numchars;
3606                                                         numchars=consolechars[0]-5;
3607                                                         if(numchars>32)numchars=32;
3608                                                         for(j=5;j<numchars+5;j++){
3609                                                         talkname[j-5]=consoletext[0][j];
3610                                                         }
3611                                                         talkname[numchars]='\0';
3612                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3613                                                         //NetworkSendInformation(chatname);
3614                                                         sprintf (playerName, "%s",talkname);
3615                                                         //NetworkSendName(playerName);
3616                                                         donesomething=1;
3617                                                         }*/
3618                                                         if(Compare(consoletext[0],"map ",0,3)){
3619                                                                 mapname[0]=':';
3620                                                                 mapname[1]='D';
3621                                                                 mapname[2]='a';
3622                                                                 mapname[3]='t';
3623                                                                 mapname[4]='a';
3624                                                                 mapname[5]=':';
3625                                                                 mapname[6]='M';
3626                                                                 mapname[7]='a';
3627                                                                 mapname[8]='p';
3628                                                                 mapname[9]='s';
3629                                                                 mapname[10]=':';
3630                                                                 for(j=4;j<consolechars[0];j++){
3631                                                                         mapname[j-4+11]=consoletext[0][j];
3632                                                                 }
3633                                                                 mapname[consolechars[0]-4+11]='\0';
3634                                                                 Loadlevel(mapname);
3635                                                                 whichlevel=-2;
3636                                                                 campaign=0;
3637                                                                 donesomething=1;
3638                                                         }
3639                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3640                                                         int v;
3641                                                         unsigned char playerNameStr[32];
3642                                                         char theIPAddress[256];
3643                                                         char thePort[32];
3644                                                         NMUInt32 port = 25710;
3645
3646                                                         strcpy(playerName, "Client");
3647                                                         GameC2PStr( playerName, playerNameStr );
3648
3649                                                         for(j=0;j<consolechars[0]-8;j++){
3650                                                         theIPAddress[j]=consoletext[0][j+8];
3651                                                         }
3652                                                         theIPAddress[consolechars[0]-8]='\0';
3653
3654                                                         sprintf( thePort, "%li", port );
3655                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3656                                                         if(v)
3657                                                         {
3658                                                         if(consolechars[0]>0){
3659                                                         for(k=14;k>=1;k--){
3660                                                         for(j=0;j<255;j++){
3661                                                         consoletext[k][j]=consoletext[k-1][j];
3662                                                         }
3663                                                         consolechars[k]=consolechars[k-1];
3664                                                         }
3665                                                         for(j=0;j<255;j++){
3666                                                         consoletext[0][j]=' ';
3667                                                         }
3668                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3669                                                         else sprintf (consoletext[0], "Could not open connection");
3670
3671                                                         consolechars[0]=255;
3672                                                         consoleselected=0;
3673                                                         }
3674                                                         }
3675                                                         else
3676                                                         {
3677                                                         donesomething=1;
3678                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3679                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3680                                                         FSOUND_SetPaused(channels[consolesuccesssound], false);
3681
3682                                                         if(consolechars[0]>0){
3683                                                         for(k=14;k>=1;k--){
3684                                                         for(j=0;j<255;j++){
3685                                                         consoletext[k][j]=consoletext[k-1][j];
3686                                                         }
3687                                                         consolechars[k]=consolechars[k-1];
3688                                                         }
3689                                                         for(j=0;j<255;j++){
3690                                                         consoletext[0][j]=' ';
3691                                                         }
3692                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3693
3694                                                         consolechars[0]=255;
3695                                                         consoleselected=0;
3696                                                         }
3697                                                         }
3698                                                         }
3699
3700                                                         if(Compare(consoletext[0],"host ",0,4)){
3701                                                         unsigned char gameNameStr[32], playerNameStr[32];
3702                                                         char gameName[32];//, playerName[32];
3703                                                         NMUInt32 port;
3704                                                         int players;
3705                                                         int v;
3706
3707                                                         port = 25710;
3708                                                         players =4;
3709
3710                                                         strcpy(gameName, "Host's game");
3711                                                         strcpy(playerName, "Host");
3712                                                         GameC2PStr( gameName, gameNameStr );
3713                                                         GameC2PStr( playerName, playerNameStr );
3714
3715                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3716                                                         if(v)
3717                                                         {
3718                                                         if(consolechars[0]>0){
3719                                                         for(k=14;k>=1;k--){
3720                                                         for(j=0;j<255;j++){
3721                                                         consoletext[k][j]=consoletext[k-1][j];
3722                                                         }
3723                                                         consolechars[k]=consolechars[k-1];
3724                                                         }
3725                                                         for(j=0;j<255;j++){
3726                                                         consoletext[0][j]=' ';
3727                                                         }
3728                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3729
3730                                                         consolechars[0]=255;
3731                                                         consoleselected=0;
3732                                                         }
3733                                                         }
3734                                                         else
3735                                                         {
3736                                                         donesomething=1;
3737                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3738                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3739                                                         FSOUND_SetPaused(channels[consolesuccesssound], false);
3740
3741                                                         if(consolechars[0]>0){
3742                                                         for(k=14;k>=1;k--){
3743                                                         for(j=0;j<255;j++){
3744                                                         consoletext[k][j]=consoletext[k-1][j];
3745                                                         }
3746                                                         consolechars[k]=consolechars[k-1];
3747                                                         }
3748                                                         for(j=0;j<255;j++){
3749                                                         consoletext[0][j]=' ';
3750                                                         }
3751                                                         sprintf (consoletext[0], "Game hosted");
3752
3753                                                         consolechars[0]=255;
3754                                                         consoleselected=0;
3755                                                         }
3756                                                         }
3757                                                         }
3758                                                         */
3759                                                         if(Compare(consoletext[0],"save ",0,4)){
3760                                                                 mapname[0]=':';
3761                                                                 mapname[1]='D';
3762                                                                 mapname[2]='a';
3763                                                                 mapname[3]='t';
3764                                                                 mapname[4]='a';
3765                                                                 mapname[5]=':';
3766                                                                 mapname[6]='M';
3767                                                                 mapname[7]='a';
3768                                                                 mapname[8]='p';
3769                                                                 mapname[9]='s';
3770                                                                 mapname[10]=':';
3771                                                                 for(j=5;j<consolechars[0];j++){
3772                                                                         mapname[j-5+11]=consoletext[0][j];
3773                                                                 }
3774                                                                 mapname[consolechars[0]-5+11]='\0';
3775
3776                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3777                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3778                                                                 FSOUND_SetPaused(channels[consolesuccesssound], false);
3779
3780                                                                 int mapvers;
3781                                                                 mapvers=12;
3782
3783
3784                                                                 FILE                    *tfile;
3785                                                                 tfile=fopen( mapname, "wb" );
3786                                                                 fpackf(tfile, "Bi", mapvers);
3787                                                                 //fpackf(tfile, "Bi", indemo);
3788                                                                 fpackf(tfile, "Bi", maptype);
3789                                                                 fpackf(tfile, "Bi", hostile);
3790                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3791                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3792                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3793                                                                 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);
3794                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3795                                                                         for(j=0;j<player[0].num_weapons;j++){
3796                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3797                                                                         }
3798
3799                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3800                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3801                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3802                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3803
3804                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3805
3806                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3807
3808                                                                         fpackf(tfile, "Bi", numdialogues);
3809                                                                         if(numdialogues)
3810                                                                                 for(k=0;k<numdialogues;k++){
3811                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3812                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3813                                                                                         for(l=0;l<10;l++){
3814                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3815                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3816                                                                                         }
3817                                                                                         if(numdialogueboxes)
3818                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3819                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3820                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3821                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3822                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3823                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3824
3825                                                                                                         templength=strlen(dialoguetext[k][l]);
3826                                                                                                         fpackf(tfile, "Bi",(templength));
3827                                                                                                         for(m=0;m<templength;m++){
3828                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3829                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3830                                                                                                         }
3831
3832                                                                                                         templength=strlen(dialoguename[k][l]);
3833                                                                                                         fpackf(tfile, "Bi",templength);
3834                                                                                                         for(m=0;m<templength;m++){
3835                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3836                                                                                                                 if(dialoguename[k][l][m]=='\0')break;
3837                                                                                                         }
3838
3839                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3840                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3841                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3842
3843                                                                                                         for(m=0;m<10;m++)
3844                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3845
3846                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3847                                                                                                 }
3848                                                                                 }
3849
3850                                                                                 if(player[0].numclothes)
3851                                                                                         for(k=0;k<player[0].numclothes;k++){
3852                                                                                                 templength=strlen(player[0].clothes[k]);
3853                                                                                                 fpackf(tfile, "Bi", templength);
3854                                                                                                 for(l=0;l<templength;l++)
3855                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3856                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
3857                                                                                         }
3858
3859                                                                                         fpackf(tfile, "Bi", environment);
3860
3861                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3862
3863                                                                                         if(objects.numobjects)
3864                                                                                                 for(k=0;k<objects.numobjects;k++){
3865                                                                                                         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]);
3866                                                                                                 }
3867
3868                                                                                                 fpackf(tfile, "Bi", numhotspots);
3869                                                                                                 if(numhotspots)
3870                                                                                                         for(i=0;i<numhotspots;i++){
3871                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3872                                                                                                                 templength=strlen(hotspottext[i]);
3873                                                                                                                 fpackf(tfile, "Bi",templength);
3874                                                                                                                 for(l=0;l<templength;l++)
3875                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3876                                                                                                         }
3877
3878                                                                                                         fpackf(tfile, "Bi", numplayers);
3879                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3880                                                                                                                 for(j=1;j<numplayers;j++){
3881                                                                                                                         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);
3882                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3883                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3884                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3885                                                                                                                                 }
3886                                                                                                                                 if(player[j].numwaypoints<30){
3887                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3888                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3889                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3890                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3891                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3892                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3893                                                                                                                                         }
3894                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3895                                                                                                                                 }
3896                                                                                                                                 else{
3897                                                                                                                                         player[j].numwaypoints=0;
3898                                                                                                                                         player[j].waypoint=0;
3899                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3900                                                                                                                                 }
3901
3902                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3903                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3904                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3905                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3906
3907                                                                                                                                 if(player[j].creature==wolftype){
3908                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3909                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3910                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3911                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3912                                                                                                                                 }
3913
3914                                                                                                                                 if(player[j].creature==rabbittype){
3915                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3916                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3917                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3918                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3919                                                                                                                                 }
3920
3921                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3922
3923
3924
3925                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3926                                                                                                                                 if(player[j].numclothes)
3927                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3928                                                                                                                                                 int templength;
3929                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3930                                                                                                                                                 fpackf(tfile, "Bi", templength);
3931                                                                                                                                                 for(l=0;l<templength;l++)
3932                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3933                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
3934                                                                                                                                         }
3935                                                                                                                 }
3936
3937                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3938                                                                                                                 if(numpathpoints)
3939                                                                                                                         for(j=0;j<numpathpoints;j++){
3940                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3941                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3942                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3943                                                                                                                                 }
3944                                                                                                                         }
3945
3946                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3947
3948
3949                                                                                                                         fclose(tfile);
3950                                                                                                                         donesomething=1;
3951
3952                                                                                                                         /*
3953                                                                                                                         FILE                    *tfile;
3954                                                                                                                         tfile=fopen( mapname, "wb" );
3955                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3956                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3957                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3958                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3959                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3960                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3961                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3962                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3963                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3964                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3965                                                                                                                         }
3966
3967                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3968                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3969                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3970                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3971                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3972                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3973                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3974                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3975                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3976                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3977                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3978
3979                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3980                                                                                                                         if(player[0].numclothes)
3981                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3982                                                                                                                         int templength;
3983                                                                                                                         templength=strlen(player[0].clothes[k]);
3984                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3985                                                                                                                         for(l=0;l<templength;l++)
3986                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3987                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);
3988                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);
3989                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);
3990                                                                                                                         }
3991
3992                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3993
3994                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3995
3996                                                                                                                         for(k=0;k<objects.numobjects;k++){
3997                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3998                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3999                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
4000                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
4001                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
4002                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
4003                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
4004                                                                                                                         }
4005
4006                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4007                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
4008                                                                                                                         for(j=1;j<numplayers;j++){
4009                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
4010                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
4011                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
4012                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
4013                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
4014                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4015                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4016                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
4017                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4018                                                                                                                         }
4019                                                                                                                         if(player[j].numwaypoints<30){
4020                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4021                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
4022                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
4023                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
4024                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
4025                                                                                                                         }
4026                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4027                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4028                                                                                                                         }
4029                                                                                                                         else{
4030                                                                                                                         player[j].numwaypoints=0;
4031                                                                                                                         player[j].waypoint=0;
4032                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4033                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4034                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4035                                                                                                                         }
4036                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
4037                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
4038                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
4039                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
4040                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
4041                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
4042                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
4043                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
4044                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
4045                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
4046                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
4047
4048                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
4049                                                                                                                         if(player[j].numclothes)
4050                                                                                                                         for(k=0;k<player[j].numclothes;k++){
4051                                                                                                                         int templength;
4052                                                                                                                         templength=strlen(player[j].clothes[k]);
4053                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
4054                                                                                                                         for(l=0;l<templength;l++)
4055                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
4056                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);
4057                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);
4058                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);
4059                                                                                                                         }
4060                                                                                                                         }
4061                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4062                                                                                                                         if(numpathpoints)
4063                                                                                                                         for(j=0;j<numpathpoints;j++){
4064                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
4065                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
4066                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
4067                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4068                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
4069                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4070                                                                                                                         }
4071                                                                                                                         }
4072
4073                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
4074                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
4075                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
4076
4077                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
4078
4079                                                                                                                         fclose(tfile);
4080                                                                                                                         donesomething=1;*/
4081                                                         }
4082                                                         /*
4083                                                         if(Compare(consoletext[0],"save ",0,4)){
4084                                                         mapname[0]=':';
4085                                                         mapname[1]='D';
4086                                                         mapname[2]='a';
4087                                                         mapname[3]='t';
4088                                                         mapname[4]='a';
4089                                                         mapname[5]=':';
4090                                                         mapname[6]='M';
4091                                                         mapname[7]='a';
4092                                                         mapname[8]='p';
4093                                                         mapname[9]='s';
4094                                                         mapname[10]=':';
4095                                                         for(j=5;j<consolechars[0];j++){
4096                                                         mapname[j-5+11]=consoletext[0][j];
4097                                                         }
4098                                                         mapname[consolechars[0]-5+11]='\0';
4099
4100                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
4101                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
4102                                                         FSOUND_SetPaused(channels[consolesuccesssound], false);
4103
4104                                                         FILE                    *tfile;
4105                                                         tfile=fopen( mapname, "wb" );
4106                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
4107                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
4108                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
4109                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
4110                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
4111                                                         for(j=0;j<player[0].num_weapons;j++){
4112                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
4113                                                         }
4114                                                         fwrite( &environment, 1, sizeof(int), tfile );
4115
4116                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
4117                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
4118                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
4119                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
4120                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
4121
4122                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4123                                                         if(numplayers>1&&numplayers<maxplayers)
4124                                                         for(j=1;j<numplayers;j++){
4125                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
4126                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4127                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4128                                                         for(k=0;k<player[j].num_weapons;k++){
4129                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4130                                                         }
4131                                                         if(player[j].numwaypoints<30){
4132                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4133                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
4134                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4135                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4136                                                         }
4137                                                         else{
4138                                                         player[j].numwaypoints=0;
4139                                                         player[j].waypoint=0;
4140                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4141                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4142                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4143                                                         }
4144                                                         }
4145                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4146                                                         if(numpathpoints)
4147                                                         for(j=0;j<numpathpoints;j++){
4148                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
4149                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4150                                                         for(k=0;k<numpathpointconnect[j];k++){
4151                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4152                                                         }
4153                                                         }
4154                                                         fclose(tfile);
4155                                                         donesomething=1;
4156                                                         }*/
4157                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
4158                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4159                                                                 donesomething=1;
4160                                                         }
4161                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
4162                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
4163                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
4164                                                         donesomething=1;
4165                                                         }*/
4166
4167                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
4168                                                                 for(j=6;j<consolechars[0];j++){
4169                                                                         mapname[j-6]=consoletext[0][j];
4170                                                                 }
4171
4172                                                                 tintr=atof(mapname);
4173
4174                                                                 donesomething=1;
4175                                                         }
4176
4177                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
4178                                                                 for(j=6;j<consolechars[0];j++){
4179                                                                         mapname[j-6]=consoletext[0][j];
4180                                                                 }
4181
4182                                                                 player[0].speedmult=atof(mapname);
4183
4184                                                                 donesomething=1;
4185                                                         }
4186
4187                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
4188                                                                 for(j=9;j<consolechars[0];j++){
4189                                                                         mapname[j-9]=consoletext[0][j];
4190                                                                 }
4191
4192                                                                 player[0].power=atof(mapname);
4193
4194                                                                 donesomething=1;
4195                                                         }
4196
4197                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
4198                                                                 for(j=13;j<consolechars[0];j++){
4199                                                                         mapname[j-13]=consoletext[0][j];
4200                                                                 }
4201
4202                                                                 viewdistance=atof(mapname)*100;
4203
4204                                                                 donesomething=1;
4205                                                         }
4206
4207                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
4208                                                                 for(j=10;j<consolechars[0];j++){
4209                                                                         mapname[j-10]=consoletext[0][j];
4210                                                                 }
4211
4212                                                                 fadestart=atof(mapname);
4213
4214                                                                 donesomething=1;
4215                                                         }
4216
4217                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
4218                                                                 for(j=6;j<consolechars[0];j++){
4219                                                                         mapname[j-6]=consoletext[0][j];
4220                                                                 }
4221
4222                                                                 player[0].power=atof(mapname);
4223
4224                                                                 donesomething=1;
4225                                                         }
4226
4227                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
4228                                                                 for(j=6;j<consolechars[0];j++){
4229                                                                         mapname[j-6]=consoletext[0][j];
4230                                                                 }
4231
4232                                                                 slomospeed=atof(mapname);
4233                                                                 slomo=1-slomo;
4234                                                                 slomodelay=1000;
4235
4236                                                                 donesomething=1;
4237                                                         }
4238
4239                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
4240                                                                 for(j=8;j<consolechars[0];j++){
4241                                                                         mapname[j-8]=consoletext[0][j];
4242                                                                 }
4243
4244                                                                 slomofreq=atoi(mapname);
4245
4246                                                                 donesomething=1;
4247                                                         }
4248
4249                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
4250                                                                 for(j=5;j<consolechars[0];j++){
4251                                                                         mapname[j-5]=consoletext[0][j];
4252                                                                 }
4253
4254                                                                 player[0].scale=atof(mapname)*.2;
4255
4256                                                                 donesomething=1;
4257                                                         }
4258
4259                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
4260                                                                 int closest=-1;
4261                                                                 float closestdist=-1;
4262                                                                 float distance;
4263                                                                 if(numplayers>1)
4264                                                                         for(i=1;i<numplayers;i++){
4265                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4266                                                                                 if(closestdist==-1||distance<closestdist){
4267                                                                                         closestdist=distance;
4268                                                                                         closest=i;
4269                                                                                 }
4270                                                                         }
4271
4272                                                                         for(j=9;j<consolechars[0];j++){
4273                                                                                 mapname[j-9]=consoletext[0][j];
4274                                                                         }
4275
4276                                                                         player[closest].scale=atof(mapname)*.2;
4277
4278                                                                         donesomething=1;
4279                                                         }
4280
4281                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
4282                                                                 int startpoint;
4283                                                                 int alldone;
4284
4285                                                                 int closest=-1;
4286                                                                 float closestdist=-1;
4287                                                                 float distance;
4288                                                                 if(numplayers>1)
4289                                                                         for(i=1;i<numplayers;i++){
4290                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4291                                                                                 if(closestdist==-1||distance<closestdist){
4292                                                                                         closestdist=distance;
4293                                                                                         closest=i;
4294                                                                                 }
4295                                                                         }
4296
4297                                                                         alldone=0;
4298                                                                         startpoint=15;
4299                                                                         j=startpoint;
4300                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4301                                                                                 mapname[j-startpoint]=consoletext[0][j];
4302                                                                                 j++;
4303                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4304                                                                         }
4305                                                                         mapname[j-startpoint]='\0';
4306
4307                                                                         headprop=atof(mapname);
4308
4309                                                                         j++;
4310                                                                         startpoint=j;
4311                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4312                                                                                 mapname[j-startpoint]=consoletext[0][j];
4313                                                                                 j++;
4314                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4315                                                                         }
4316                                                                         mapname[j-startpoint]='\0';
4317
4318                                                                         bodyprop=atof(mapname);
4319
4320                                                                         j++;
4321                                                                         startpoint=j;
4322                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4323                                                                                 mapname[j-startpoint]=consoletext[0][j];
4324                                                                                 j++;
4325                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4326                                                                         }
4327                                                                         mapname[j-startpoint]='\0';
4328
4329                                                                         armprop=atof(mapname);
4330
4331                                                                         j++;
4332                                                                         startpoint=j;
4333                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4334                                                                                 mapname[j-startpoint]=consoletext[0][j];
4335                                                                                 j++;
4336                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4337                                                                         }
4338                                                                         mapname[j-startpoint]='\0';
4339
4340                                                                         legprop=atof(mapname);
4341
4342                                                                         if(player[closest].creature==wolftype){
4343                                                                                 player[closest].proportionhead=1.1*headprop;
4344                                                                                 player[closest].proportionbody=1.1*bodyprop;
4345                                                                                 player[closest].proportionarms=1.1*armprop;
4346                                                                                 player[closest].proportionlegs=1.1*legprop;
4347                                                                         }
4348
4349                                                                         if(player[closest].creature==rabbittype){
4350                                                                                 player[closest].proportionhead=1.2*headprop;
4351                                                                                 player[closest].proportionbody=1.05*bodyprop;
4352                                                                                 player[closest].proportionarms=1.00*armprop;
4353                                                                                 player[closest].proportionlegs=1.1*legprop;
4354                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4355                                                                         }
4356
4357                                                                         donesomething=1;
4358                                                         }
4359
4360
4361                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4362                                                                 for(i=1;i<numplayers;i++){
4363                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4364                                                                 }
4365
4366                                                                 donesomething=1;
4367                                                         }
4368
4369                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4370                                                                 for(j=9;j<consolechars[0];j++){
4371                                                                         mapname[j-9]=consoletext[0][j];
4372                                                                 }
4373
4374                                                                 tutoriallevel=atoi(mapname);
4375
4376                                                                 donesomething=1;
4377                                                         }
4378
4379
4380                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4381                                                                 for(j=6;j<consolechars[0];j++){
4382                                                                         mapname[j-6]=consoletext[0][j];
4383                                                                 }
4384
4385                                                                 tintg=atof(mapname);
4386
4387                                                                 donesomething=1;
4388                                                         }
4389
4390                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4391                                                                 for(j=6;j<consolechars[0];j++){
4392                                                                         mapname[j-6]=consoletext[0][j];
4393                                                                 }
4394
4395                                                                 tintb=atof(mapname);
4396
4397                                                                 donesomething=1;
4398                                                         }
4399
4400                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4401                                                                 for(j=8;j<consolechars[0];j++){
4402                                                                         mapname[j-8]=consoletext[0][j];
4403                                                                 }
4404
4405                                                                 hostile=atoi(mapname);
4406
4407                                                                 donesomething=1;
4408                                                         }
4409
4410
4411                                                         if(Compare(consoletext[0],"type active ",0,11)){
4412                                                                 editoractive=typeactive;
4413
4414                                                                 donesomething=1;
4415                                                         }
4416
4417                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4418                                                                 indemo=1;
4419                                                                 hotspot[numhotspots]=player[0].coords;
4420                                                                 hotspotsize[numhotspots]=0;
4421                                                                 hotspottype[numhotspots]=-111;
4422                                                                 mapname[0]='\0';
4423                                                                 strcpy(hotspottext[numhotspots],"mapname");
4424                                                                 numhotspots++;
4425
4426                                                                 donesomething=1;
4427                                                         }
4428
4429                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4430                                                                 indemo=0;
4431                                                                 numhotspots--;
4432
4433                                                                 donesomething=1;
4434                                                         }
4435
4436                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4437                                                                 editoractive=typesitting;
4438
4439                                                                 donesomething=1;
4440                                                         }
4441
4442                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4443                                                                 editoractive=typesittingwall;
4444
4445                                                                 donesomething=1;
4446                                                         }
4447
4448                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4449                                                                 editoractive=typesleeping;
4450
4451                                                                 donesomething=1;
4452                                                         }
4453                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4454                                                                 editoractive=typedead1;
4455
4456                                                                 donesomething=1;
4457                                                         }
4458                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4459                                                                 editoractive=typedead2;
4460
4461                                                                 donesomething=1;
4462                                                         }
4463                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4464                                                                 editoractive=typedead3;
4465                                                                 donesomething=1;
4466                                                         }
4467                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4468                                                                 editoractive=typedead4;
4469
4470                                                                 donesomething=1;
4471                                                         }
4472
4473                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4474                                                                 editorpathtype=wpkeepwalking;
4475
4476                                                                 donesomething=1;
4477                                                         }
4478
4479                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4480                                                                 editorpathtype=wppause;
4481
4482                                                                 donesomething=1;
4483                                                         }
4484
4485                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4486                                                                 maptype=mapkilleveryone;
4487
4488                                                                 donesomething=1;
4489                                                         }
4490
4491                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4492                                                                 maptype=mapgosomewhere;
4493
4494                                                                 donesomething=1;
4495                                                         }
4496
4497                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4498                                                                 maptype=mapkillsomeone;
4499
4500                                                                 donesomething=1;
4501
4502                                                         }
4503
4504                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4505                                                                 maptype=mapkillmost;
4506
4507                                                                 donesomething=1;
4508
4509                                                         }
4510
4511                                                         if(Compare(consoletext[0],"hs ",0,2)){
4512                                                                 int startpoint;
4513                                                                 int alldone;
4514
4515                                                                 hotspot[numhotspots]=player[0].coords;
4516
4517                                                                 alldone=0;
4518                                                                 startpoint=3;
4519                                                                 j=startpoint;
4520                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4521                                                                         mapname[j-startpoint]=consoletext[0][j];
4522                                                                         j++;
4523                                                                         if(consoletext[0][j]=='\0')alldone=1;
4524                                                                 }
4525                                                                 mapname[j-startpoint]='\0';
4526
4527                                                                 hotspotsize[numhotspots]=atof(mapname);
4528
4529                                                                 j++;
4530                                                                 startpoint=j;
4531                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4532                                                                         mapname[j-startpoint]=consoletext[0][j];
4533                                                                         j++;
4534                                                                         if(consoletext[0][j]=='\0')alldone=1;
4535                                                                 }
4536                                                                 mapname[j-startpoint]='\0';
4537
4538                                                                 hotspottype[numhotspots]=atoi(mapname);
4539
4540                                                                 j++;
4541                                                                 startpoint=j;
4542                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4543                                                                         mapname[j-startpoint]=consoletext[0][j];
4544                                                                         j++;
4545                                                                         if(consoletext[0][j]=='\0')alldone=1;
4546                                                                 }
4547                                                                 mapname[j-startpoint]='\n';
4548                                                                 mapname[j-startpoint+1]='\0';
4549
4550                                                                 strcpy(hotspottext[numhotspots],mapname);
4551
4552                                                                 numhotspots++;
4553
4554                                                                 donesomething=1;
4555                                                         }
4556
4557                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4558                                                                 int startpoint;
4559                                                                 int alldone;
4560
4561                                                                 alldone=0;
4562                                                                 startpoint=9;
4563                                                                 j=startpoint;
4564                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4565                                                                         mapname[j-startpoint]=consoletext[0][j];
4566                                                                         j++;
4567                                                                         if(consoletext[0][j]=='\0')alldone=1;
4568                                                                 }
4569                                                                 mapname[j-startpoint]='\0';
4570                                                                 startpoint=j+1;
4571
4572                                                                 dialoguetype[numdialogues]=atoi(mapname);
4573
4574                                                                 mapname[0]=':';
4575                                                                 mapname[1]='D';
4576                                                                 mapname[2]='a';
4577                                                                 mapname[3]='t';
4578                                                                 mapname[4]='a';
4579                                                                 mapname[5]=':';
4580                                                                 mapname[6]='D';
4581                                                                 mapname[7]='i';
4582                                                                 mapname[8]='a';
4583                                                                 mapname[9]='l';
4584                                                                 mapname[10]='o';
4585                                                                 mapname[11]='g';
4586                                                                 mapname[12]='u';
4587                                                                 mapname[13]='e';
4588                                                                 mapname[14]='s';
4589                                                                 mapname[15]=':';
4590                                                                 for(j=startpoint;j<consolechars[0];j++){
4591                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4592                                                                 }
4593                                                                 mapname[consolechars[0]-startpoint+16]='.';
4594                                                                 mapname[consolechars[0]-startpoint+17]='t';
4595                                                                 mapname[consolechars[0]-startpoint+18]='x';
4596                                                                 mapname[consolechars[0]-startpoint+19]='t';
4597                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4598
4599                                                                 for(j=0;j<max_dialoguelength;j++){
4600                                                                         for(k=0;k<128;k++){
4601                                                                                 dialoguetext[numdialogues][j][k]='\0';
4602                                                                         }
4603                                                                         for(k=0;k<64;k++){
4604                                                                                 dialoguename[numdialogues][j][k]='\0';
4605                                                                         }
4606                                                                 }
4607
4608                                                                 ifstream ipstream(ConvertFileName(mapname));
4609                                                                 ipstream.ignore(256,':');
4610                                                                 ipstream >> numdialogueboxes[numdialogues];
4611                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4612                                                                         ipstream.ignore(256,':');
4613                                                                         ipstream.ignore(256,':');
4614                                                                         ipstream.ignore(256,' ');
4615                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4616                                                                         ipstream.ignore(256,':');
4617                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4618                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4619                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4620                                                                         ipstream.ignore(256,':');
4621                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4622                                                                         ipstream.ignore(256,':');
4623                                                                         ipstream.ignore(256,' ');
4624                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4625                                                                         for(j=0;j<128;j++){
4626                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4627                                                                         }
4628                                                                         ipstream.ignore(256,':');
4629                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4630                                                                 }
4631
4632                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4633                                                                         for(j=0;j<numplayers;j++){
4634                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4635                                                                         }
4636                                                                 }
4637                                                                 ipstream.close();
4638
4639                                                                 directing=1;
4640                                                                 indialogue=0;
4641                                                                 whichdialogue=numdialogues;
4642
4643
4644                                                                 numdialogues++;
4645
4646                                                                 donesomething=1;
4647                                                         }
4648
4649                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4650                                                                 int startpoint;
4651                                                                 int alldone;
4652                                                                 int whichdi;
4653
4654                                                                 alldone=0;
4655                                                                 startpoint=12;
4656                                                                 j=startpoint;
4657                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4658                                                                         mapname[j-startpoint]=consoletext[0][j];
4659                                                                         j++;
4660                                                                         if(consoletext[0][j]=='\0')alldone=1;
4661                                                                 }
4662                                                                 mapname[j-startpoint]='\0';
4663                                                                 startpoint=j+1;
4664
4665                                                                 whichdi=atoi(mapname);
4666
4667                                                                 mapname[0]=':';
4668                                                                 mapname[1]='D';
4669                                                                 mapname[2]='a';
4670                                                                 mapname[3]='t';
4671                                                                 mapname[4]='a';
4672                                                                 mapname[5]=':';
4673                                                                 mapname[6]='D';
4674                                                                 mapname[7]='i';
4675                                                                 mapname[8]='a';
4676                                                                 mapname[9]='l';
4677                                                                 mapname[10]='o';
4678                                                                 mapname[11]='g';
4679                                                                 mapname[12]='u';
4680                                                                 mapname[13]='e';
4681                                                                 mapname[14]='s';
4682                                                                 mapname[15]=':';
4683                                                                 for(j=startpoint;j<consolechars[0];j++){
4684                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4685                                                                 }
4686                                                                 mapname[consolechars[0]-startpoint+16]='.';
4687                                                                 mapname[consolechars[0]-startpoint+17]='t';
4688                                                                 mapname[consolechars[0]-startpoint+18]='x';
4689                                                                 mapname[consolechars[0]-startpoint+19]='t';
4690                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4691
4692                                                                 for(j=0;j<max_dialoguelength;j++){
4693                                                                         for(k=0;k<128;k++){
4694                                                                                 dialoguetext[whichdi][j][k]='\0';
4695                                                                         }
4696                                                                         for(k=0;k<64;k++){
4697                                                                                 dialoguename[whichdi][j][k]='\0';
4698                                                                         }
4699                                                                 }
4700
4701                                                                 ifstream ipstream(ConvertFileName(mapname));
4702                                                                 ipstream.ignore(256,':');
4703                                                                 ipstream >> numdialogueboxes[whichdi];
4704                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4705                                                                         ipstream.ignore(256,':');
4706                                                                         ipstream.ignore(256,':');
4707                                                                         ipstream.ignore(256,' ');
4708                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4709                                                                         ipstream.ignore(256,':');
4710                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4711                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4712                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4713                                                                         ipstream.ignore(256,':');
4714                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4715                                                                         ipstream.ignore(256,':');
4716                                                                         ipstream.ignore(256,' ');
4717                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4718                                                                         for(j=0;j<128;j++){
4719                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4720                                                                         }
4721                                                                         ipstream.ignore(256,':');
4722                                                                         ipstream >> dialogueboxsound[whichdi][i];
4723                                                                 }
4724
4725                                                                 ipstream.close();
4726
4727                                                                 donesomething=1;
4728                                                         }
4729
4730                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4731                                                                 int startpoint;
4732                                                                 int alldone;
4733                                                                 int whichdi;
4734
4735                                                                 alldone=0;
4736                                                                 startpoint=8;
4737                                                                 j=startpoint;
4738                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4739                                                                         mapname[j-startpoint]=consoletext[0][j];
4740                                                                         j++;
4741                                                                         if(consoletext[0][j]=='\0')alldone=1;
4742                                                                 }
4743                                                                 mapname[j-startpoint]='\0';
4744                                                                 dialoguetype[0]=atoi(mapname);
4745
4746                                                                 startpoint=j+1;
4747
4748                                                                 donesomething=1;
4749                                                         }
4750
4751
4752                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4753                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4754
4755                                                                 donesomething=1;
4756                                                         }
4757
4758                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4759                                                                 numdialogues--;
4760                                                                 if(numdialogues<0)numdialogues=0;
4761
4762                                                                 donesomething=1;
4763                                                         }
4764
4765                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4766                                                                 player[0].immobile=1;
4767                                                                 donesomething=1;
4768                                                         }
4769
4770                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4771                                                                 player[0].immobile=0;
4772                                                                 donesomething=1;
4773                                                         }
4774
4775                                                         if(Compare(consoletext[0],"play ",0,4)){
4776                                                                 int startpoint;
4777                                                                 int alldone;
4778
4779                                                                 alldone=0;
4780                                                                 startpoint=5;
4781                                                                 j=startpoint;
4782                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4783                                                                         mapname[j-startpoint]=consoletext[0][j];
4784                                                                         j++;
4785                                                                         if(consoletext[0][j]=='\0')alldone=1;
4786                                                                 }
4787                                                                 mapname[j-startpoint]='\0';
4788                                                                 startpoint=j+1;
4789
4790                                                                 whichdialogue=atoi(mapname);
4791
4792                                                                 if(numdialogues>whichdialogue){
4793                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4794                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4795                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4796                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4797                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4798                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4799                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4800                                                                         }
4801
4802                                                                         directing=0;
4803                                                                         indialogue=0;
4804
4805                                                                         donesomething=1;
4806
4807                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4808                                                                         float gLoc[3];
4809                                                                         float vel[3];
4810                                                                         XYZ temppos;
4811                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4812                                                                         temppos=temppos-viewer;
4813                                                                         Normalise(&temppos);
4814                                                                         temppos+=viewer;
4815
4816                                                                         gLoc[0]=temppos.x;
4817                                                                         gLoc[1]=temppos.y;
4818                                                                         gLoc[2]=temppos.z;
4819                                                                         vel[0]=0;
4820                                                                         vel[1]=0;
4821                                                                         vel[2]=0;
4822                                                                         int whichsoundplay;
4823                                                                         whichsoundplay=rabbitchitter;
4824                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4825                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4826                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4827                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4828                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4829                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4830                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4831                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4832                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4833                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4834                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4835                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4836                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4837                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4838                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4839                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4840                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4841                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4842                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4843                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4844                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4845                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
4846                                                                         FSOUND_SetPaused(channels[whichsoundplay], false);
4847                                                                         //}
4848                                                                 }
4849                                                         }
4850
4851
4852
4853
4854                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4855                                                                 numhotspots--;
4856                                                                 if(numhotspots<0)numhotspots=0;
4857                                                                 donesomething=1;
4858                                                         }
4859
4860
4861                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4862                                                                 int startpoint;
4863                                                                 int alldone;
4864
4865                                                                 alldone=0;
4866                                                                 startpoint=11;
4867                                                                 j=startpoint;
4868                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4869                                                                         mapname[j-startpoint]=consoletext[0][j];
4870                                                                         j++;
4871                                                                         if(consoletext[0][j]=='\0')alldone=1;
4872                                                                 }
4873                                                                 mapname[j-startpoint]='\0';
4874
4875                                                                 headprop=atof(mapname);
4876
4877                                                                 j++;
4878                                                                 startpoint=j;
4879                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4880                                                                         mapname[j-startpoint]=consoletext[0][j];
4881                                                                         j++;
4882                                                                         if(consoletext[0][j]=='\0')alldone=1;
4883                                                                 }
4884                                                                 mapname[j-startpoint]='\0';
4885
4886                                                                 bodyprop=atof(mapname);
4887
4888                                                                 j++;
4889                                                                 startpoint=j;
4890                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4891                                                                         mapname[j-startpoint]=consoletext[0][j];
4892                                                                         j++;
4893                                                                         if(consoletext[0][j]=='\0')alldone=1;
4894                                                                 }
4895                                                                 mapname[j-startpoint]='\0';
4896
4897                                                                 armprop=atof(mapname);
4898
4899                                                                 j++;
4900                                                                 startpoint=j;
4901                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4902                                                                         mapname[j-startpoint]=consoletext[0][j];
4903                                                                         j++;
4904                                                                         if(consoletext[0][j]=='\0')alldone=1;
4905                                                                 }
4906                                                                 mapname[j-startpoint]='\0';
4907
4908                                                                 legprop=atof(mapname);
4909
4910                                                                 if(player[0].creature==wolftype){
4911                                                                         player[0].proportionhead=1.1*headprop;
4912                                                                         player[0].proportionbody=1.1*bodyprop;
4913                                                                         player[0].proportionarms=1.1*armprop;
4914                                                                         player[0].proportionlegs=1.1*legprop;
4915                                                                 }
4916
4917                                                                 if(player[0].creature==rabbittype){
4918                                                                         player[0].proportionhead=1.2*headprop;
4919                                                                         player[0].proportionbody=1.05*bodyprop;
4920                                                                         player[0].proportionarms=1.00*armprop;
4921                                                                         player[0].proportionlegs=1.1*legprop;
4922                                                                         player[0].proportionlegs.y=1.05*legprop;
4923                                                                 }
4924
4925                                                                 donesomething=1;
4926                                                         }
4927
4928                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4929                                                                 for(i=0;i<numplayers;i++){
4930                                                                         if(i>0)player[i].immobile=1;
4931                                                                 }
4932                                                                 donesomething=1;
4933                                                         }
4934
4935
4936                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4937                                                                 player[0].armorhead=1;
4938                                                                 player[0].armorhigh=1;
4939                                                                 player[0].armorlow=1;
4940                                                                 player[0].protectionhead=1;
4941                                                                 player[0].protectionhigh=1;
4942                                                                 player[0].protectionlow=1;
4943                                                                 player[0].metalhead=1;
4944                                                                 player[0].metalhigh=1;
4945                                                                 player[0].metallow=1;
4946                                                                 player[0].power=1;
4947                                                                 player[0].speedmult=1;
4948                                                                 player[0].scale=1;
4949
4950                                                                 if(player[0].creature==wolftype){
4951                                                                         player[0].proportionhead=1.1;
4952                                                                         player[0].proportionbody=1.1;
4953                                                                         player[0].proportionarms=1.1;
4954                                                                         player[0].proportionlegs=1.1;
4955                                                                 }
4956
4957                                                                 if(player[0].creature==rabbittype){
4958                                                                         player[0].proportionhead=1.2;
4959                                                                         player[0].proportionbody=1.05;
4960                                                                         player[0].proportionarms=1.00;
4961                                                                         player[0].proportionlegs=1.1;
4962                                                                         player[0].proportionlegs.y=1.05;
4963                                                                 }
4964
4965                                                                 player[0].numclothes=0;
4966                                                                 if(player[0].whichskin==0){
4967                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4968                                                                 }
4969                                                                 else if(player[0].whichskin==1){
4970                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4971                                                                 }
4972                                                                 else if(player[0].whichskin==2){
4973                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4974                                                                 }
4975                                                                 else if(player[0].whichskin==3){
4976                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4977                                                                 }
4978                                                                 else if(player[0].whichskin==4){
4979                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4980                                                                 }
4981                                                                 else if(player[0].whichskin==5){
4982                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4983                                                                 }
4984                                                                 else if(player[0].whichskin==6){
4985                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4986                                                                 }
4987                                                                 else if(player[0].whichskin==7){
4988                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4989                                                                 }
4990                                                                 else if(player[0].whichskin==8){
4991                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4992                                                                 }
4993                                                                 else if(player[0].whichskin==9){
4994                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4995                                                                 }
4996
4997                                                                 editoractive=typeactive;
4998                                                                 player[0].immobile=0;
4999
5000
5001
5002                                                                 donesomething=1;
5003                                                         }
5004
5005                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
5006                                                                 int startpoint;
5007                                                                 int alldone;
5008                                                                 alldone=0;
5009                                                                 startpoint=5;
5010                                                                 j=startpoint;
5011                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5012                                                                         mapname[j-startpoint]=consoletext[0][j];
5013                                                                         j++;
5014                                                                         if(consoletext[0][j]=='\0')alldone=1;
5015                                                                 }
5016                                                                 mapname[j-startpoint]='\0';
5017
5018                                                                 tintr=atof(mapname);
5019
5020                                                                 j++;
5021                                                                 startpoint=j;
5022                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5023                                                                         mapname[j-startpoint]=consoletext[0][j];
5024                                                                         j++;
5025                                                                         if(consoletext[0][j]=='\0')alldone=1;
5026                                                                 }
5027                                                                 mapname[j-startpoint]='\0';
5028
5029                                                                 tintg=atof(mapname);
5030
5031                                                                 j++;
5032                                                                 startpoint=j;
5033                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5034                                                                         mapname[j-startpoint]=consoletext[0][j];
5035                                                                         j++;
5036                                                                         if(consoletext[0][j]=='\0')alldone=1;
5037                                                                 }
5038                                                                 mapname[j-startpoint]='\0';
5039
5040                                                                 tintb=atof(mapname);
5041
5042                                                                 donesomething=1;
5043                                                         }
5044
5045                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
5046                                                                 int startpoint;
5047                                                                 int alldone;
5048                                                                 alldone=0;
5049                                                                 startpoint=9;
5050                                                                 j=startpoint;
5051                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5052                                                                         mapname[j-startpoint]=consoletext[0][j];
5053                                                                         j++;
5054                                                                         if(consoletext[0][j]=='\0')alldone=1;
5055                                                                 }
5056                                                                 mapname[j-startpoint]='\0';
5057
5058                                                                 skyboxr=atof(mapname);
5059
5060                                                                 j++;
5061                                                                 startpoint=j;
5062                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5063                                                                         mapname[j-startpoint]=consoletext[0][j];
5064                                                                         j++;
5065                                                                         if(consoletext[0][j]=='\0')alldone=1;
5066                                                                 }
5067                                                                 mapname[j-startpoint]='\0';
5068
5069                                                                 skyboxg=atof(mapname);
5070
5071                                                                 j++;
5072                                                                 startpoint=j;
5073                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5074                                                                         mapname[j-startpoint]=consoletext[0][j];
5075                                                                         j++;
5076                                                                         if(consoletext[0][j]=='\0')alldone=1;
5077                                                                 }
5078                                                                 mapname[j-startpoint]='\0';
5079
5080                                                                 skyboxb=atof(mapname);
5081
5082                                                                 skyboxlightr=skyboxr;
5083                                                                 skyboxlightg=skyboxg;
5084                                                                 skyboxlightb=skyboxb;
5085
5086                                                                 SetUpLighting();
5087
5088                                                                 //if(skyboxtexture){
5089                                                                 terrain.DoShadows();
5090                                                                 objects.DoShadows();
5091                                                                 /*}
5092                                                                 else terrain.DoLighting();
5093                                                                 */
5094                                                                 donesomething=1;
5095                                                         }
5096
5097                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
5098                                                                 int startpoint;
5099                                                                 int alldone;
5100                                                                 alldone=0;
5101                                                                 startpoint=10;
5102                                                                 j=startpoint;
5103                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5104                                                                         mapname[j-startpoint]=consoletext[0][j];
5105                                                                         j++;
5106                                                                         if(consoletext[0][j]=='\0')alldone=1;
5107                                                                 }
5108                                                                 mapname[j-startpoint]='\0';
5109
5110                                                                 skyboxlightr=atof(mapname);
5111
5112                                                                 j++;
5113                                                                 startpoint=j;
5114                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5115                                                                         mapname[j-startpoint]=consoletext[0][j];
5116                                                                         j++;
5117                                                                         if(consoletext[0][j]=='\0')alldone=1;
5118                                                                 }
5119                                                                 mapname[j-startpoint]='\0';
5120
5121                                                                 skyboxlightg=atof(mapname);
5122
5123                                                                 j++;
5124                                                                 startpoint=j;
5125                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5126                                                                         mapname[j-startpoint]=consoletext[0][j];
5127                                                                         j++;
5128                                                                         if(consoletext[0][j]=='\0')alldone=1;
5129                                                                 }
5130                                                                 mapname[j-startpoint]='\0';
5131
5132                                                                 skyboxlightb=atof(mapname);
5133
5134                                                                 SetUpLighting();
5135
5136                                                                 //if(skyboxtexture){
5137                                                                 terrain.DoShadows();
5138                                                                 objects.DoShadows();
5139                                                                 /*}
5140                                                                 else terrain.DoLighting();
5141                                                                 */
5142                                                                 donesomething=1;
5143                                                         }
5144
5145                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
5146                                                                 skyboxtexture=1-skyboxtexture;
5147
5148                                                                 SetUpLighting();
5149                                                                 //if(skyboxtexture){
5150                                                                 terrain.DoShadows();
5151                                                                 objects.DoShadows();
5152                                                                 /*}
5153                                                                 else terrain.DoLighting();
5154                                                                 */
5155                                                                 donesomething=1;
5156                                                         }
5157
5158                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
5159                                                                 int startpoint;
5160                                                                 int alldone;
5161                                                                 alldone=0;
5162                                                                 startpoint=11;
5163                                                                 j=startpoint;
5164                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5165                                                                         mapname[j-startpoint]=consoletext[0][j];
5166                                                                         j++;
5167                                                                         if(consoletext[0][j]=='\0')alldone=1;
5168                                                                 }
5169                                                                 mapname[j-startpoint]='\0';
5170
5171                                                                 player[0].protectionhead=atof(mapname);
5172
5173                                                                 j++;
5174                                                                 startpoint=j;
5175                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5176                                                                         mapname[j-startpoint]=consoletext[0][j];
5177                                                                         j++;
5178                                                                         if(consoletext[0][j]=='\0')alldone=1;
5179                                                                 }
5180                                                                 mapname[j-startpoint]='\0';
5181
5182                                                                 player[0].protectionhigh=atof(mapname);
5183
5184                                                                 j++;
5185                                                                 startpoint=j;
5186                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5187                                                                         mapname[j-startpoint]=consoletext[0][j];
5188                                                                         j++;
5189                                                                         if(consoletext[0][j]=='\0')alldone=1;
5190                                                                 }
5191                                                                 mapname[j-startpoint]='\0';
5192
5193                                                                 player[0].protectionlow=atof(mapname);
5194
5195                                                                 donesomething=1;
5196                                                         }
5197
5198                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
5199                                                                 int startpoint;
5200                                                                 int alldone;
5201                                                                 alldone=0;
5202                                                                 startpoint=6;
5203                                                                 j=startpoint;
5204                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5205                                                                         mapname[j-startpoint]=consoletext[0][j];
5206                                                                         j++;
5207                                                                         if(consoletext[0][j]=='\0')alldone=1;
5208                                                                 }
5209                                                                 mapname[j-startpoint]='\0';
5210
5211                                                                 player[0].armorhead=atof(mapname);
5212
5213                                                                 j++;
5214                                                                 startpoint=j;
5215                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5216                                                                         mapname[j-startpoint]=consoletext[0][j];
5217                                                                         j++;
5218                                                                         if(consoletext[0][j]=='\0')alldone=1;
5219                                                                 }
5220                                                                 mapname[j-startpoint]='\0';
5221
5222                                                                 player[0].armorhigh=atof(mapname);
5223
5224                                                                 j++;
5225                                                                 startpoint=j;
5226                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5227                                                                         mapname[j-startpoint]=consoletext[0][j];
5228                                                                         j++;
5229                                                                         if(consoletext[0][j]=='\0')alldone=1;
5230                                                                 }
5231                                                                 mapname[j-startpoint]='\0';
5232
5233                                                                 player[0].armorlow=atof(mapname);
5234
5235                                                                 donesomething=1;
5236                                                         }
5237
5238                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
5239                                                                 for(i=0;i<numplayers;i++){
5240                                                                         player[i].protectionhead=1.0;
5241                                                                         player[i].protectionhigh=1.0;
5242                                                                         player[i].protectionlow=1.0;
5243                                                                         player[i].armorhead=1.0;
5244                                                                         player[i].armorhigh=1.0;
5245                                                                         player[i].armorlow=1.0;
5246                                                                 }
5247
5248                                                                 donesomething=1;
5249                                                         }
5250
5251                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
5252                                                                 int closest=-1;
5253                                                                 float closestdist=-1;
5254                                                                 float distance;
5255                                                                 if(numplayers>1)
5256                                                                         for(i=1;i<numplayers;i++){
5257                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5258                                                                                 if(closestdist==-1||distance<closestdist){
5259                                                                                         closestdist=distance;
5260                                                                                         closest=i;
5261                                                                                 }
5262                                                                         }
5263
5264                                                                         int startpoint;
5265                                                                         int alldone;
5266                                                                         alldone=0;
5267                                                                         startpoint=15;
5268                                                                         j=startpoint;
5269                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5270                                                                                 mapname[j-startpoint]=consoletext[0][j];
5271                                                                                 j++;
5272                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5273                                                                         }
5274                                                                         mapname[j-startpoint]='\0';
5275
5276                                                                         player[closest].protectionhead=atof(mapname);
5277
5278                                                                         j++;
5279                                                                         startpoint=j;
5280                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5281                                                                                 mapname[j-startpoint]=consoletext[0][j];
5282                                                                                 j++;
5283                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5284                                                                         }
5285                                                                         mapname[j-startpoint]='\0';
5286
5287                                                                         player[closest].protectionhigh=atof(mapname);
5288
5289                                                                         j++;
5290                                                                         startpoint=j;
5291                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5292                                                                                 mapname[j-startpoint]=consoletext[0][j];
5293                                                                                 j++;
5294                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5295                                                                         }
5296                                                                         mapname[j-startpoint]='\0';
5297
5298                                                                         player[closest].protectionlow=atof(mapname);
5299
5300                                                                         donesomething=1;
5301                                                         }
5302
5303                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
5304                                                                 int closest=-1;
5305                                                                 float closestdist=-1;
5306                                                                 float distance;
5307                                                                 if(numplayers>1)
5308                                                                         for(i=1;i<numplayers;i++){
5309                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5310                                                                                 if(closestdist==-1||distance<closestdist){
5311                                                                                         closestdist=distance;
5312                                                                                         closest=i;
5313                                                                                 }
5314                                                                         }
5315                                                                         int startpoint;
5316                                                                         int alldone;
5317                                                                         alldone=0;
5318                                                                         startpoint=10;
5319                                                                         j=startpoint;
5320                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5321                                                                                 mapname[j-startpoint]=consoletext[0][j];
5322                                                                                 j++;
5323                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5324                                                                         }
5325                                                                         mapname[j-startpoint]='\0';
5326
5327                                                                         player[closest].armorhead=atof(mapname);
5328
5329                                                                         j++;
5330                                                                         startpoint=j;
5331                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5332                                                                                 mapname[j-startpoint]=consoletext[0][j];
5333                                                                                 j++;
5334                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5335                                                                         }
5336                                                                         mapname[j-startpoint]='\0';
5337
5338                                                                         player[closest].armorhigh=atof(mapname);
5339
5340                                                                         j++;
5341                                                                         startpoint=j;
5342                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5343                                                                                 mapname[j-startpoint]=consoletext[0][j];
5344                                                                                 j++;
5345                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5346                                                                         }
5347                                                                         mapname[j-startpoint]='\0';
5348
5349                                                                         player[closest].armorlow=atof(mapname);
5350
5351                                                                         donesomething=1;
5352                                                         }
5353
5354
5355                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5356                                                                 int startpoint;
5357                                                                 int alldone;
5358                                                                 alldone=0;
5359                                                                 startpoint=6;
5360                                                                 j=startpoint;
5361                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5362                                                                         mapname[j-startpoint]=consoletext[0][j];
5363                                                                         j++;
5364                                                                         if(consoletext[0][j]=='\0')alldone=1;
5365                                                                 }
5366                                                                 mapname[j-startpoint]='\0';
5367
5368                                                                 player[0].metalhead=atof(mapname);
5369
5370                                                                 j++;
5371                                                                 startpoint=j;
5372                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5373                                                                         mapname[j-startpoint]=consoletext[0][j];
5374                                                                         j++;
5375                                                                         if(consoletext[0][j]=='\0')alldone=1;
5376                                                                 }
5377                                                                 mapname[j-startpoint]='\0';
5378
5379                                                                 player[0].metalhigh=atof(mapname);
5380
5381                                                                 j++;
5382                                                                 startpoint=j;
5383                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5384                                                                         mapname[j-startpoint]=consoletext[0][j];
5385                                                                         j++;
5386                                                                         if(consoletext[0][j]=='\0')alldone=1;
5387                                                                 }
5388
5389                                                                 mapname[j-startpoint]='\0';
5390
5391                                                                 player[0].metallow=atof(mapname);
5392
5393                                                                 donesomething=1;
5394                                                         }
5395
5396                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5397                                                                 int closest=-1;
5398                                                                 float closestdist=-1;
5399                                                                 float distance;
5400                                                                 if(numplayers>1)
5401                                                                         for(i=1;i<numplayers;i++){
5402                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5403                                                                                 if(closestdist==-1||distance<closestdist){
5404                                                                                         closestdist=distance;
5405                                                                                         closest=i;
5406                                                                                 }
5407                                                                         }
5408                                                                         player[closest].numclothes=0;
5409                                                                         if(player[closest].whichskin==0){
5410                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5411                                                                         }
5412                                                                         else if(player[closest].whichskin==1){
5413                                                                                 LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5414                                                                         }
5415                                                                         else if(player[closest].whichskin==2){
5416                                                                                 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5417                                                                         }
5418                                                                         else if(player[closest].whichskin==3){
5419                                                                                 LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5420                                                                         }
5421                                                                         else if(player[closest].whichskin==4){
5422                                                                                 LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5423                                                                         }
5424                                                                         else if(player[closest].whichskin==5){
5425                                                                                 LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5426                                                                         }
5427                                                                         else if(player[closest].whichskin==6){
5428                                                                                 LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5429                                                                         }
5430                                                                         else if(player[closest].whichskin==7){
5431                                                                                 LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5432                                                                         }
5433                                                                         else if(player[closest].whichskin==8){
5434                                                                                 LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5435                                                                         }
5436                                                                         else if(player[closest].whichskin==9){
5437                                                                                 LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5438                                                                         }
5439
5440                                                                         donesomething=1;
5441                                                         }
5442
5443                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5444                                                                 int closest=0;
5445
5446                                                                 player[closest].numclothes=0;
5447                                                                 if(player[closest].whichskin==0){
5448                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5449                                                                 }
5450                                                                 else if(player[closest].whichskin==1){
5451                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5452                                                                 }
5453                                                                 else if(player[closest].whichskin==2){
5454                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5455                                                                 }
5456                                                                 else if(player[closest].whichskin==3){
5457                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5458                                                                 }
5459                                                                 else if(player[closest].whichskin==4){
5460                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5461                                                                 }
5462                                                                 else if(player[closest].whichskin==5){
5463                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5464                                                                 }
5465                                                                 else if(player[closest].whichskin==6){
5466                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5467                                                                 }
5468                                                                 else if(player[closest].whichskin==7){
5469                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5470                                                                 }
5471                                                                 else if(player[closest].whichskin==8){
5472                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5473                                                                 }
5474                                                                 else if(player[closest].whichskin==9){
5475                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5476                                                                 }
5477
5478                                                                 donesomething=1;
5479                                                         }
5480
5481                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5482                                                                 mapname[0]=':';
5483                                                                 mapname[1]='D';
5484                                                                 mapname[2]='a';
5485                                                                 mapname[3]='t';
5486                                                                 mapname[4]='a';
5487                                                                 mapname[5]=':';
5488                                                                 mapname[6]='T';
5489                                                                 mapname[7]='e';
5490                                                                 mapname[8]='x';
5491                                                                 mapname[9]='t';
5492                                                                 mapname[10]='u';
5493                                                                 mapname[11]='r';
5494                                                                 mapname[12]='e';
5495                                                                 mapname[13]='s';
5496                                                                 mapname[14]=':';
5497                                                                 for(j=8;j<consolechars[0];j++){
5498                                                                         mapname[j-8+15]=consoletext[0][j];
5499                                                                 }
5500                                                                 mapname[consolechars[0]-8+15]='.';
5501                                                                 mapname[consolechars[0]-8+16]='p';
5502                                                                 mapname[consolechars[0]-8+17]='n';
5503                                                                 mapname[consolechars[0]-8+18]='g';
5504                                                                 mapname[consolechars[0]-8+19]='\0';
5505
5506                                                                 //:Data:Textures:Pants.png
5507
5508                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5509                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5510                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5511                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5512                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5513                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5514                                                                         player[0].numclothes++;
5515                                                                 }
5516
5517                                                                 donesomething=1;
5518                                                         }
5519
5520                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5521                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5522
5523                                                                 donesomething=1;
5524                                                         }
5525
5526                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5527                                                                 cellophane=1-cellophane;
5528
5529                                                                 if(cellophane){
5530                                                                         for(i=0;i<numplayers;i++){
5531                                                                                 player[i].proportionhead.z=0;
5532                                                                                 player[i].proportionbody.z=0;
5533                                                                                 player[i].proportionarms.z=0;
5534                                                                                 player[i].proportionlegs.z=0;
5535                                                                         }
5536                                                                 }
5537
5538                                                                 if(!cellophane){
5539                                                                         for(i=0;i<numplayers;i++){
5540                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5541                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5542                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5543                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5544                                                                         }
5545                                                                 }
5546
5547                                                                 donesomething=1;
5548                                                         }
5549
5550                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5551                                                                 mapname[0]=':';
5552                                                                 mapname[1]='D';
5553                                                                 mapname[2]='a';
5554                                                                 mapname[3]='t';
5555                                                                 mapname[4]='a';
5556                                                                 mapname[5]=':';
5557                                                                 mapname[6]='T';
5558                                                                 mapname[7]='e';
5559                                                                 mapname[8]='x';
5560                                                                 mapname[9]='t';
5561                                                                 mapname[10]='u';
5562                                                                 mapname[11]='r';
5563                                                                 mapname[12]='e';
5564                                                                 mapname[13]='s';
5565                                                                 mapname[14]=':';
5566                                                                 for(j=12;j<consolechars[0];j++){
5567                                                                         mapname[j-12+15]=consoletext[0][j];
5568                                                                 }
5569                                                                 mapname[consolechars[0]-12+15]='.';
5570                                                                 mapname[consolechars[0]-12+16]='p';
5571                                                                 mapname[consolechars[0]-12+17]='n';
5572                                                                 mapname[consolechars[0]-12+18]='g';
5573                                                                 mapname[consolechars[0]-12+19]='\0';
5574
5575                                                                 //:Data:Textures:Pants.png
5576                                                                 int closest=-1;
5577                                                                 float closestdist=-1;
5578                                                                 float distance;
5579                                                                 if(numplayers>1)
5580                                                                         for(i=1;i<numplayers;i++){
5581                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5582                                                                                 if(closestdist==-1||distance<closestdist){
5583                                                                                         closestdist=distance;
5584                                                                                         closest=i;
5585                                                                                 }
5586                                                                         }
5587
5588                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5589                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5590                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5591                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5592                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5593                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5594                                                                                 player[closest].numclothes++;
5595                                                                         }
5596
5597                                                                         donesomething=1;
5598                                                         }
5599
5600                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5601                                                                 player[0].skeleton.id=0;
5602                                                                 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);
5603                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5604                                                                 player[0].creature=rabbittype;
5605                                                                 player[0].scale=.2;
5606
5607                                                                 player[0].proportionhead=1.2;
5608                                                                 player[0].proportionbody=1.05;
5609                                                                 player[0].proportionarms=1.00;
5610                                                                 player[0].proportionlegs=1.1;
5611                                                                 player[0].proportionlegs.y=1.05;
5612                                                                 player[0].headless=0;
5613
5614                                                                 player[0].damagetolerance=200;
5615
5616                                                                 donesomething=1;
5617                                                         }
5618                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5619                                                                 player[0].skeleton.id=0;
5620                                                                 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);
5621                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5622                                                                 player[0].creature=wolftype;
5623
5624                                                                 player[0].proportionhead=1.1;
5625                                                                 player[0].proportionbody=1.1;
5626                                                                 player[0].proportionarms=1.1;
5627                                                                 player[0].proportionlegs=1.1;
5628                                                                 player[0].proportionlegs.y=1.1;
5629                                                                 player[0].scale=.23;
5630
5631                                                                 player[0].damagetolerance=300;
5632
5633                                                                 donesomething=1;
5634                                                         }
5635                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5636                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5637                                                         donesomething=1;
5638                                                         }
5639                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5640                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5641                                                         donesomething=1;
5642                                                         }
5643                                                         if(Compare(consoletext[0],"david ",0,5)){
5644                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5645                                                         donesomething=1;
5646                                                         }*/
5647                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5648                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5649                                                                 donesomething=1;
5650                                                         }
5651                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5652                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5653                                                                 donesomething=1;
5654                                                         }
5655                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5656                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5657                                                                 donesomething=1;
5658                                                         }/*
5659                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5660                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5661                                                          donesomething=1;
5662                                                          }*/
5663                                                         if(Compare(consoletext[0],"white ",0,5)){
5664                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5665                                                                 donesomething=1;
5666                                                         }
5667                                                         if(Compare(consoletext[0],"brown ",0,5)){
5668                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5669                                                                 donesomething=1;
5670                                                         }
5671                                                         if(Compare(consoletext[0],"black ",0,5)){
5672                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5673                                                                 donesomething=1;
5674                                                         }
5675                                                         if(consolechars[0]>0){
5676                                                                 for(k=14;k>=1;k--){
5677                                                                         for(j=0;j<255;j++){
5678                                                                                 consoletext[k][j]=consoletext[k-1][j];
5679                                                                         }
5680                                                                         consolechars[k]=consolechars[k-1];
5681                                                                 }
5682                                                                 for(j=0;j<255;j++){
5683                                                                         consoletext[0][j]=' ';
5684                                                                 }
5685                                                                 consolechars[0]=0;
5686                                                                 consoleselected=0;
5687
5688                                                                 if(!donesomething){
5689                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
5690                                                                         FSOUND_SetVolume(channels[consolefailsound], 256);
5691                                                                         FSOUND_SetPaused(channels[consolefailsound], false);
5692                                                                 }
5693                                                         }
5694                                                 }
5695                                         }
5696                                         togglekey[i]=1;
5697                                 }
5698                                 else {
5699                                         togglekey[i]=0;
5700                                         togglekeydelay[i]=0;
5701                                 }
5702                         }
5703
5704                         consoleblinkdelay-=multiplier;
5705                         if(consoleblinkdelay<=0){
5706                                 consoleblinkdelay=.3;
5707                                 consoleblink=1-consoleblink;
5708                         }
5709                 }
5710
5711                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5712                         tryquit=1;
5713                         if(mainmenu==3){
5714                                 if(newdetail>2)newdetail=detail;
5715                                 if(newdetail<0)newdetail=detail;
5716 #if !USE_SDL  // we'll take anything that works.
5717                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
5718                                 if(newscreenheight>3000)newscreenheight=screenheight;
5719 #endif
5720                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5721                                 if(newscreenheight<0)newscreenheight=screenheight;
5722
5723                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5724                                 opstream << "Screenwidth:\n";
5725                                 opstream << newscreenwidth;
5726                                 opstream << "\nScreenheight:\n";
5727                                 opstream << newscreenheight;
5728                                 opstream << "\nMouse sensitivity:\n";
5729                                 opstream << usermousesensitivity;
5730                                 opstream << "\nBlur(0,1):\n";
5731                                 opstream << ismotionblur;
5732                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5733                                 opstream << newdetail;
5734                                 opstream << "\nFloating jump:\n";
5735                                 opstream << floatjump;
5736                                 opstream << "\nMouse jump:\n";
5737                                 opstream << mousejump;
5738                                 opstream << "\nAmbient sound:\n";
5739                                 opstream << ambientsound;
5740                                 opstream << "\nBlood (0,1,2):\n";
5741                                 opstream << bloodtoggle;
5742                                 opstream << "\nAuto slomo:\n";
5743                                 opstream << autoslomo;
5744                                 opstream << "\nFoliage:\n";
5745                                 opstream << foliage;
5746                                 opstream << "\nMusic:\n";
5747                                 opstream << musictoggle;
5748                                 opstream << "\nTrilinear:\n";
5749                                 opstream << trilinear;
5750                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5751                                 opstream << decals;
5752                                 opstream << "\nInvert mouse:\n";
5753                                 opstream << invertmouse;
5754                                 opstream << "\nGamespeed:\n";
5755                                 if(oldgamespeed==0)oldgamespeed=1;
5756                                 opstream << oldgamespeed;
5757                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5758                                 opstream << difficulty;
5759                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5760                                 opstream << damageeffects;
5761                                 opstream << "\nText:\n";
5762                                 opstream << texttoggle;
5763                                 opstream << "\nDebug:\n";
5764                                 opstream << debugmode;
5765                                 opstream << "\nVBL Sync:\n";
5766                                 opstream << vblsync;
5767                                 opstream << "\nShow Points:\n";
5768                                 opstream << showpoints;
5769                                 opstream << "\nAlways Blur:\n";
5770                                 opstream << alwaysblur;
5771                                 opstream << "\nImmediate mode (turn on on G5):\n";
5772                                 opstream << immediate;
5773                                 opstream << "\nVelocity blur:\n";
5774                                 opstream << velocityblur;
5775                             opstream << "\nVolume:\n";
5776                         opstream << volume;
5777                                 opstream << "\nForward key:\n";
5778                                 opstream << KeyToChar(forwardkey);
5779                                 opstream << "\nBack key:\n";
5780                                 opstream << KeyToChar(backkey);
5781                                 opstream << "\nLeft key:\n";
5782                                 opstream << KeyToChar(leftkey);
5783                                 opstream << "\nRight key:\n";
5784                                 opstream << KeyToChar(rightkey);
5785                                 opstream << "\nJump key:\n";
5786                                 opstream << KeyToChar(jumpkey);
5787                                 opstream << "\nCrouch key:\n";
5788                                 opstream << KeyToChar(crouchkey);
5789                                 opstream << "\nDraw key:\n";
5790                                 opstream << KeyToChar(drawkey);
5791                                 opstream << "\nThrow key:\n";
5792                                 opstream << KeyToChar(throwkey);
5793                                 opstream << "\nAttack key:\n";
5794                                 opstream << KeyToChar(attackkey);
5795                                 opstream << "\nChat key:\n";
5796                                 opstream << KeyToChar(chatkey);
5797                                 opstream.close();
5798                         }
5799                 }
5800
5801                 static int oldwinfreeze;
5802                 if(winfreeze&&!oldwinfreeze){
5803                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
5804                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
5805                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
5806                         FSOUND_SetPaused(channels[consolesuccesssound], false);
5807                 }
5808                 if(winfreeze==0)oldwinfreeze=winfreeze;
5809                 else oldwinfreeze++;
5810
5811                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5812                         if(winfreeze)winfreeze=0;
5813                         oldjumpkeydown=1;
5814                 }
5815                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5816                         if(winfreeze){
5817                                 mainmenu=9;
5818                                 gameon=0;
5819                         }
5820                 }
5821                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5822                         oldjumpkeydown=1;
5823                 }
5824                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5825
5826                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5827
5828                         static bool oldbuttondialogue;
5829
5830                         if(indialogue!=-1)talkdelay=1;
5831                         talkdelay-=multiplier;
5832
5833                         if(talkdelay<=0)
5834                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5835                                         for(i=0;i<numdialogues;i++){
5836                                                 int realdialoguetype;
5837                                                 bool special;
5838                                                 if(dialoguetype[i]>49){
5839                                                         realdialoguetype=dialoguetype[i]-50;
5840                                                         special=1;
5841                                                 }
5842                                                 else if(dialoguetype[i]>39){
5843                                                         realdialoguetype=dialoguetype[i]-40;
5844                                                         special=1;
5845                                                 }
5846                                                 else if(dialoguetype[i]>29){
5847                                                         realdialoguetype=dialoguetype[i]-30;
5848                                                         special=1;
5849                                                 }
5850                                                 else if(dialoguetype[i]>19){
5851                                                         realdialoguetype=dialoguetype[i]-20;
5852                                                         special=1;
5853                                                 }
5854                                                 else if(dialoguetype[i]>9){
5855                                                         realdialoguetype=dialoguetype[i]-10;
5856                                                         special=1;
5857                                                 }
5858                                                 else {
5859                                                         realdialoguetype=dialoguetype[i];
5860                                                         special=0;
5861                                                 }
5862                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5863                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5864                                                                 whichdialogue=i;
5865                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5866                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5867                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5868                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5869                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5870                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5871                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5872                                                                 }
5873                                                                 directing=0;
5874                                                                 indialogue=0;
5875                                                                 dialoguetime=0;
5876                                                                 dialoguegonethrough[i]++;
5877                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5878                                                                         static float gLoc[3];
5879                                                                         static float vel[3];
5880                                                                         XYZ temppos;
5881                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5882                                                                         temppos=temppos-viewer;
5883                                                                         Normalise(&temppos);
5884                                                                         temppos+=viewer;
5885
5886                                                                         gLoc[0]=temppos.x;
5887                                                                         gLoc[1]=temppos.y;
5888                                                                         gLoc[2]=temppos.z;vel[0]=0;
5889                                                                         vel[1]=0;
5890                                                                         vel[2]=0;
5891                                                                         int whichsoundplay;
5892                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5893                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5894                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5895                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5896                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5897                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5898                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5899                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5900                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5901                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5902                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5903                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5904                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5905                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5906                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5907                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5908                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5909                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5910                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5911                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5912                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
5913                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5914                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
5915                                                                         FSOUND_SetPaused(channels[whichsoundplay], false);
5916                                                                 }
5917                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5918                                                         }
5919                                                 }
5920                                         }
5921
5922                                         windvar+=multiplier;
5923                                         smoketex+=multiplier;
5924                                         tutorialstagetime+=multiplier;
5925
5926                                         static float hotspotvisual[40];
5927                                         if(numhotspots){
5928                                                 XYZ hotspotsprite;
5929                                                 if(editorenabled)
5930                                                         for(i=0;i<numhotspots;i++)
5931                                                                 hotspotvisual[i]-=multiplier/320;
5932
5933                                                 for(i=0;i<numhotspots;i++){
5934                                                         //if(hotspottype[i]<=10)
5935                                                         while(hotspotvisual[i]<0){
5936                                                                 hotspotsprite=0;
5937                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5938                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5939                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5940                                                                 hotspotsprite+=hotspot[i];
5941                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5942                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5943                                                         }
5944                                                 }
5945
5946                                                 for(i=0;i<numhotspots;i++){
5947                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5948                                                                 hotspot[i]=player[hotspottype[i]].coords;
5949                                                         }
5950                                                 }
5951                                         }
5952
5953                                         //Tutorial
5954                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5955                                                 tutorialstage++;
5956                                                 tutorialsuccess=0;
5957                                                 if(tutorialstage<=1){
5958                                                         canattack=0;
5959                                                         cananger=0;
5960                                                         reversaltrain=0;
5961                                                 }
5962                                                 if(tutorialstage==1){
5963                                                         tutorialmaxtime=5;
5964                                                 }
5965                                                 if(tutorialstage==2){
5966                                                         tutorialmaxtime=2;
5967                                                 }
5968                                                 if(tutorialstage==3){
5969                                                         tutorialmaxtime=600;
5970                                                 }
5971                                                 if(tutorialstage==4){
5972                                                         tutorialmaxtime=1000;
5973                                                 }
5974                                                 if(tutorialstage==5){
5975                                                         tutorialmaxtime=600;
5976                                                 }
5977                                                 if(tutorialstage==6){
5978                                                         tutorialmaxtime=600;
5979                                                 }
5980                                                 if(tutorialstage==7){
5981                                                         tutorialmaxtime=600;
5982                                                 }
5983                                                 if(tutorialstage==8){
5984                                                         tutorialmaxtime=600;
5985                                                 }
5986                                                 if(tutorialstage==9){
5987                                                         tutorialmaxtime=600;
5988                                                 }
5989                                                 if(tutorialstage==10){
5990                                                         tutorialmaxtime=2;
5991                                                 }
5992                                                 if(tutorialstage==11){
5993                                                         tutorialmaxtime=1000;
5994                                                 }
5995                                                 if(tutorialstage==12){
5996                                                         tutorialmaxtime=1000;
5997                                                 }
5998                                                 if(tutorialstage==13){
5999                                                         tutorialmaxtime=2;
6000                                                 }
6001                                                 if(tutorialstage==14){
6002                                                         tutorialmaxtime=3;
6003
6004                                                         XYZ temp,temp2;
6005
6006                                                         temp.x=1011;
6007                                                         temp.y=84;
6008                                                         temp.z=491;
6009                                                         temp2.x=1025;
6010                                                         temp2.y=75;
6011                                                         temp2.z=447;
6012
6013                                                         player[1].coords=(temp+temp2)/2;
6014
6015                                                         float gLoc[3];
6016                                                         float vel[3];
6017                                                         gLoc[0]=player[1].coords.x;
6018                                                         gLoc[1]=player[1].coords.y;
6019                                                         gLoc[2]=player[1].coords.z;
6020                                                         vel[0]=0;
6021                                                         vel[1]=0;
6022                                                         vel[2]=0;
6023                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6024                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6025                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6026                                                         FSOUND_SetPaused(channels[fireendsound], false);
6027
6028                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6029                                                                 if(Random()%2==0){
6030                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6031                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6032                                                                         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;
6033                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6034                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6035                                                                 }
6036                                                         }
6037
6038                                                 }
6039                                                 if(tutorialstage==15){
6040                                                         tutorialmaxtime=500;
6041                                                 }
6042                                                 if(tutorialstage==16){
6043                                                         tutorialmaxtime=500;
6044                                                 }
6045                                                 if(tutorialstage==17){
6046                                                         tutorialmaxtime=500;
6047                                                 }
6048                                                 if(tutorialstage==18){
6049                                                         tutorialmaxtime=500;
6050                                                 }
6051                                                 if(tutorialstage==19){
6052                                                         tutorialstage=20;
6053                                                         //tutorialmaxtime=500;
6054                                                 }
6055                                                 if(tutorialstage==20){
6056                                                         tutorialmaxtime=500;
6057                                                 }
6058                                                 if(tutorialstage==21){
6059                                                         tutorialmaxtime=500;
6060                                                         if(bonus==cannon){
6061                                                                 bonus=Slicebonus;
6062                                                                 againbonus=1;
6063                                                         }
6064                                                         else againbonus=0;
6065                                                 }
6066                                                 if(tutorialstage==22){
6067                                                         tutorialmaxtime=500;
6068                                                 }
6069                                                 if(tutorialstage==23){
6070                                                         tutorialmaxtime=500;
6071                                                 }
6072                                                 if(tutorialstage==24){
6073                                                         tutorialmaxtime=500;
6074                                                 }
6075                                                 if(tutorialstage==25){
6076                                                         tutorialmaxtime=500;
6077                                                 }
6078                                                 if(tutorialstage==26){
6079                                                         tutorialmaxtime=2;
6080                                                 }
6081                                                 if(tutorialstage==27){
6082                                                         tutorialmaxtime=4;
6083                                                         reversaltrain=1;
6084                                                         cananger=1;
6085                                                         player[1].aitype=attacktypecutoff;
6086                                                 }
6087                                                 if(tutorialstage==28){
6088                                                         tutorialmaxtime=400;
6089                                                 }
6090                                                 if(tutorialstage==29){
6091                                                         tutorialmaxtime=400;
6092                                                         player[0].escapednum=0;
6093                                                 }
6094                                                 if(tutorialstage==30){
6095                                                         tutorialmaxtime=4;
6096                                                         reversaltrain=0;
6097                                                         cananger=0;
6098                                                         player[1].aitype=passivetype;
6099                                                 }
6100                                                 if(tutorialstage==31){
6101                                                         tutorialmaxtime=13;
6102                                                 }
6103                                                 if(tutorialstage==32){
6104                                                         tutorialmaxtime=8;
6105                                                 }
6106                                                 if(tutorialstage==33){
6107                                                         tutorialmaxtime=400;
6108                                                         cananger=1;
6109                                                         canattack=1;
6110                                                         player[1].aitype=attacktypecutoff;
6111                                                 }
6112                                                 if(tutorialstage==34){
6113                                                         tutorialmaxtime=400;
6114                                                 }
6115                                                 if(tutorialstage==35){
6116                                                         tutorialmaxtime=400;
6117                                                 }
6118                                                 if(tutorialstage==36){
6119                                                         tutorialmaxtime=2;
6120                                                         reversaltrain=0;
6121                                                         cananger=0;
6122                                                         player[1].aitype=passivetype;
6123                                                 }
6124                                                 if(tutorialstage==37){
6125                                                         damagedealt=0;
6126                                                         damagetaken=0;
6127                                                         tutorialmaxtime=50;
6128                                                         cananger=1;
6129                                                         canattack=1;
6130                                                         player[1].aitype=attacktypecutoff;
6131                                                 }
6132                                                 if(tutorialstage==38){
6133                                                         tutorialmaxtime=4;
6134                                                         canattack=0;
6135                                                         cananger=0;
6136                                                         player[1].aitype=passivetype;
6137                                                 }
6138                                                 if(tutorialstage==39){
6139                                                         XYZ temp,temp2;
6140
6141                                                         temp.x=1011;
6142                                                         temp.y=84;
6143                                                         temp.z=491;
6144                                                         temp2.x=1025;
6145                                                         temp2.y=75;
6146                                                         temp2.z=447;
6147
6148
6149                                                         weapons.owner[weapons.numweapons]=-1;
6150                                                         weapons.type[weapons.numweapons]=knife;
6151                                                         weapons.damage[weapons.numweapons]=0;
6152                                                         weapons.mass[weapons.numweapons]=1;
6153                                                         weapons.tipmass[weapons.numweapons]=1.2;
6154                                                         weapons.length[weapons.numweapons]=.25;
6155                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6156                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6157
6158                                                         weapons.velocity[weapons.numweapons]=0.1;
6159                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6160                                                         weapons.missed[weapons.numweapons]=1;
6161                                                         weapons.hitsomething[weapons.numweapons]=0;
6162                                                         weapons.freetime[weapons.numweapons]=0;
6163                                                         weapons.firstfree[weapons.numweapons]=1;
6164                                                         weapons.physics[weapons.numweapons]=1;
6165
6166                                                         weapons.numweapons++;
6167                                                 }
6168                                                 if(tutorialstage==40){
6169                                                         tutorialmaxtime=300;
6170                                                 }
6171                                                 if(tutorialstage==41){
6172                                                         tutorialmaxtime=300;
6173                                                 }
6174                                                 if(tutorialstage==42){
6175                                                         tutorialmaxtime=8;
6176                                                 }
6177                                                 if(tutorialstage==43){
6178                                                         tutorialmaxtime=300;
6179                                                 }
6180                                                 if(tutorialstage==44){
6181                                                         weapons.owner[0]=1;
6182                                                         player[0].weaponactive=-1;
6183                                                         player[0].num_weapons=0;
6184                                                         player[1].weaponactive=0;
6185                                                         player[1].num_weapons=1;
6186                                                         player[1].weaponids[0]=0;
6187
6188                                                         cananger=1;
6189                                                         canattack=1;
6190                                                         player[1].aitype=attacktypecutoff;
6191
6192                                                         tutorialmaxtime=300;
6193                                                 }
6194                                                 if(tutorialstage==45){
6195                                                         weapons.owner[0]=1;
6196                                                         player[0].weaponactive=-1;
6197                                                         player[0].num_weapons=0;
6198                                                         player[1].weaponactive=0;
6199                                                         player[1].num_weapons=1;
6200                                                         player[1].weaponids[0]=0;
6201
6202                                                         tutorialmaxtime=300;
6203                                                 }
6204                                                 if(tutorialstage==46){
6205                                                         weapons.owner[0]=1;
6206                                                         player[0].weaponactive=-1;
6207                                                         player[0].num_weapons=0;
6208                                                         player[1].weaponactive=0;
6209                                                         player[1].num_weapons=1;
6210                                                         player[1].weaponids[0]=0;
6211
6212                                                         weapons.type[0]=sword;
6213
6214                                                         tutorialmaxtime=300;
6215                                                 }
6216
6217                                                 if(tutorialstage==47){
6218                                                         tutorialmaxtime=10;
6219
6220                                                         XYZ temp,temp2;
6221
6222                                                         temp.x=1011;
6223                                                         temp.y=84;
6224                                                         temp.z=491;
6225                                                         temp2.x=1025;
6226                                                         temp2.y=75;
6227                                                         temp2.z=447;
6228
6229                                                         weapons.owner[weapons.numweapons]=-1;
6230                                                         weapons.type[weapons.numweapons]=sword;
6231                                                         weapons.damage[weapons.numweapons]=0;
6232                                                         weapons.mass[weapons.numweapons]=1;
6233                                                         weapons.tipmass[weapons.numweapons]=1.2;
6234                                                         weapons.length[weapons.numweapons]=.25;
6235                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6236                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6237
6238                                                         weapons.velocity[weapons.numweapons]=0.1;
6239                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6240                                                         weapons.missed[weapons.numweapons]=1;
6241                                                         weapons.hitsomething[weapons.numweapons]=0;
6242                                                         weapons.freetime[weapons.numweapons]=0;
6243                                                         weapons.firstfree[weapons.numweapons]=1;
6244                                                         weapons.physics[weapons.numweapons]=1;
6245
6246                                                         weapons.owner[0]=1;
6247                                                         weapons.owner[1]=0;
6248                                                         player[0].weaponactive=0;
6249                                                         player[0].num_weapons=1;
6250                                                         player[0].weaponids[0]=1;
6251                                                         player[1].weaponactive=0;
6252                                                         player[1].num_weapons=1;
6253                                                         player[1].weaponids[0]=0;
6254
6255                                                         weapons.numweapons++;
6256                                                 }
6257                                                 if(tutorialstage==48){
6258                                                         canattack=0;
6259                                                         cananger=0;
6260                                                         player[1].aitype=passivetype;
6261
6262                                                         tutorialmaxtime=15;
6263
6264                                                         weapons.owner[0]=1;
6265                                                         weapons.owner[1]=0;
6266                                                         player[0].weaponactive=0;
6267                                                         player[0].num_weapons=1;
6268                                                         player[0].weaponids[0]=1;
6269                                                         player[1].weaponactive=0;
6270                                                         player[1].num_weapons=1;
6271                                                         player[1].weaponids[0]=0;
6272
6273                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
6274                                                         else weapons.type[0]=staff;
6275
6276                                                         weapons.numweapons++;
6277                                                 }
6278                                                 if(tutorialstage==49){
6279                                                         canattack=0;
6280                                                         cananger=0;
6281                                                         player[1].aitype=passivetype;
6282
6283                                                         tutorialmaxtime=200;
6284
6285                                                         weapons.position[1]=1000;
6286                                                         weapons.tippoint[1]=1000;
6287
6288                                                         weapons.numweapons=1;
6289                                                         weapons.owner[0]=0;
6290                                                         player[1].weaponactive=-1;
6291                                                         player[1].num_weapons=0;
6292                                                         player[0].weaponactive=0;
6293                                                         player[0].num_weapons=1;
6294                                                         player[0].weaponids[0]=0;
6295
6296                                                         weapons.type[0]=knife;
6297
6298                                                         weapons.numweapons++;
6299                                                 }
6300                                                 if(tutorialstage==50){
6301                                                         tutorialmaxtime=8;
6302
6303                                                         XYZ temp,temp2;
6304                                                         float gLoc[3];
6305                                                         float vel[3];
6306                                                         gLoc[0]=player[1].coords.x;
6307                                                         gLoc[1]=player[1].coords.y;
6308                                                         gLoc[2]=player[1].coords.z;
6309                                                         vel[0]=0;
6310                                                         vel[1]=0;
6311                                                         vel[2]=0;
6312                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6313                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6314                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6315                                                         FSOUND_SetPaused(channels[fireendsound], false);
6316
6317                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6318                                                                 if(Random()%2==0){
6319                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6320                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6321                                                                         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;
6322                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6323                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6324                                                                 }
6325                                                         }
6326
6327                                                         player[1].num_weapons=0;
6328                                                         player[1].weaponstuck=-1;
6329                                                         player[1].weaponactive=-1;
6330
6331                                                         weapons.numweapons=0;
6332
6333                                                         weapons.owner[0]=-1;
6334                                                         weapons.velocity[0]=0.1;
6335                                                         weapons.tipvelocity[0]=-0.1;
6336                                                         weapons.missed[0]=1;
6337                                                         weapons.hitsomething[0]=0;
6338                                                         weapons.freetime[0]=0;
6339                                                         weapons.firstfree[0]=1;
6340                                                         weapons.physics[0]=1;
6341                                                 }
6342                                                 if(tutorialstage==51){
6343                                                         tutorialmaxtime=80000;
6344                                                 }
6345                                                 if(tutorialstage<=51)tutorialstagetime=0;
6346                                         }
6347
6348                                         //Tutorial success
6349                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6350                                                 if(tutorialstage==3){
6351                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6352                                                 }
6353                                                 if(tutorialstage==4){
6354                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6355                                                 }
6356                                                 if(tutorialstage==5){
6357                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6358                                                 }
6359                                                 if(tutorialstage==6){
6360                                                         if(player[0].isCrouch())tutorialsuccess=1;
6361                                                 }
6362                                                 if(tutorialstage==7){
6363                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6364                                                 }
6365                                                 if(tutorialstage==8){
6366                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6367                                                 }
6368                                                 if(tutorialstage==9){
6369                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6370                                                 }
6371                                                 if(tutorialstage==11){
6372                                                         if(player[0].isWallJump())tutorialsuccess=1;
6373                                                 }
6374                                                 if(tutorialstage==12){
6375                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6376                                                 }
6377                                                 if(tutorialstage==15){
6378                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6379                                                 }
6380                                                 if(tutorialstage==16){
6381                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6382                                                 }
6383                                                 if(tutorialstage==17){
6384                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6385                                                 }
6386                                                 if(tutorialstage==18){
6387                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6388                                                 }
6389                                                 if(tutorialstage==19){
6390                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6391                                                 }
6392                                                 if(tutorialstage==20){
6393                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6394                                                 }
6395                                                 if(tutorialstage==21){
6396                                                         if(bonus==cannon)tutorialsuccess=1;
6397                                                 }
6398                                                 if(tutorialstage==22){
6399                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6400                                                 }
6401                                                 if(tutorialstage==23){
6402                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6403                                                 }
6404                                                 if(tutorialstage==24){
6405                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6406                                                 }
6407                                                 if(tutorialstage==25){
6408                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6409                                                 }
6410                                                 if(tutorialstage==28){
6411                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6412                                                 }
6413                                                 if(tutorialstage==29){
6414                                                         if(player[0].escapednum==2){
6415                                                                 tutorialsuccess=1;
6416                                                                 reversaltrain=0;
6417                                                                 cananger=0;
6418                                                                 player[1].aitype=passivetype;
6419                                                         }
6420                                                 }
6421                                                 if(tutorialstage==33){
6422                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6423                                                 }
6424                                                 if(tutorialstage==34){
6425                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6426                                                 }
6427                                                 if(tutorialstage==35){
6428                                                         if(animation[player[0].targetanimation].attack==reversal){
6429                                                                 tutorialsuccess=1;
6430                                                                 reversaltrain=0;
6431                                                                 cananger=0;
6432                                                                 player[1].aitype=passivetype;
6433                                                         }
6434                                                 }
6435                                                 if(tutorialstage==40){
6436                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6437                                                 }
6438                                                 if(tutorialstage==41){
6439                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6440                                                 }
6441                                                 if(tutorialstage==43){
6442                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6443                                                 }
6444                                                 if(tutorialstage==44){
6445                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6446                                                 }
6447                                                 if(tutorialstage==45){
6448                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6449                                                 }
6450                                                 if(tutorialstage==46){
6451                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6452                                                 }
6453                                                 if(tutorialstage==49){
6454                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6455                                                 }
6456                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6457
6458
6459                                                 if(tutorialstagetime==tutorialmaxtime-3){
6460                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6461                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6462                                                         FSOUND_SetPaused(channels[consolesuccesssound], false);
6463                                                 }
6464
6465                                                 if(tutorialsuccess>=1){
6466                                                         if(tutorialstage==34||tutorialstage==35)
6467                                                                 tutorialstagetime=tutorialmaxtime-1;
6468                                                 }
6469                                         }
6470
6471                                         if(tutoriallevel){
6472                                                 if(tutorialstage<14||tutorialstage>=50){
6473                                                         player[1].coords.y=300;
6474                                                         player[1].velocity=0;
6475                                                 }
6476                                         }
6477
6478                                         if(tutoriallevel!=1){
6479                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6480                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6481                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6482                                                         FSOUND_SetPaused(channels[consolesuccesssound], false);
6483                                                 }
6484                                         }
6485                                         else
6486                                                 if(bonustime==0){
6487                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6488                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6489                                                         FSOUND_SetPaused(channels[fireendsound], false);
6490                                                 }
6491                                                 if(bonustime==0){
6492                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6493                                                         else bonusnum[bonus]+=0.15;
6494                                                         if(tutoriallevel)bonusvalue=0;
6495                                                         bonusvalue/=bonusnum[bonus];
6496                                                         bonustotal+=bonusvalue;
6497                                                 }
6498                                                 bonustime+=multiplier;
6499
6500                                                 if(environment==snowyenvironment){
6501                                                         precipdelay-=multiplier;
6502                                                         while(precipdelay<0){
6503                                                                 precipdelay+=.04;
6504                                                                 if(!detail)precipdelay+=.04;
6505                                                                 XYZ footvel,footpoint;
6506
6507                                                                 footvel=0;
6508                                                                 footpoint=viewer+viewerfacing*6;
6509                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6510                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6511                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6512                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6513                                                         }
6514                                                 }
6515                                                 for(k=0;k<numplayers;k++){
6516                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6517                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6518
6519                                                         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){
6520                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6521                                                                 else if(player[k].rotation>player[k].targetrotation){
6522                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6523                                                                 }
6524                                                                 else if(player[k].rotation<player[k].targetrotation){
6525                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6526                                                                 }
6527                                                         }
6528
6529
6530                                                         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))){
6531                                                                 player[k].turnspeed*=2;
6532                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6533                                                                 else if(player[k].rotation>player[k].targetrotation){
6534                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6535                                                                 }
6536                                                                 else if(player[k].rotation<player[k].targetrotation){
6537                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6538                                                                 }
6539                                                                 player[k].turnspeed/=2;
6540                                                         }
6541
6542                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6543                                                                 player[k].turnspeed*=4;
6544                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6545                                                                 else if(player[k].rotation>player[k].targetrotation){
6546                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6547                                                                 }
6548                                                                 else if(player[k].rotation<player[k].targetrotation){
6549                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6550                                                                 }
6551                                                                 player[k].turnspeed/=4;
6552                                                         }
6553
6554                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6555                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6556
6557                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6558                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6559                                                                         bool tempcollide=0;
6560
6561                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6562                                                                         if(player[k].collide>1)player[k].collide=1;
6563                                                                         player[k].collide-=multiplier*30;
6564
6565                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6566                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6567                                                                         }
6568                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6569                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6570                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6571                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6572                                                                                                 lowpoint=player[k].coords;
6573                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6574                                                                                                 else lowpoint.y+=1.3;
6575                                                                                                 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){
6576                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6577                                                                                                 }
6578                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6579                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6580                                                                                                 */
6581                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6582                                                                                                         flatfacing=lowpoint-player[k].coords;
6583                                                                                                         player[k].coords=lowpoint;
6584                                                                                                         player[k].coords.y-=1.3;
6585                                                                                                         player[k].collide=1;
6586                                                                                                         tempcollide=1;
6587                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6588                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6589                                                                                                                 tempcoords1=lowpoint;
6590                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6591                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6592                                                                                                                         player[k].target=0;
6593                                                                                                                         player[k].targetanimation=walljumpleftanim;
6594                                                                                                                         player[k].targetframe=0;
6595                                                                                                                         float gLoc[3];
6596                                                                                                                         float vel[3];
6597                                                                                                                         gLoc[0]=player[k].coords.x;
6598                                                                                                                         gLoc[1]=player[k].coords.y;
6599                                                                                                                         gLoc[2]=player[k].coords.z;
6600                                                                                                                         vel[0]=0;
6601                                                                                                                         vel[1]=0;
6602                                                                                                                         vel[2]=0;
6603                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6604                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6605                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6606                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], false);
6607                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], true);
6608
6609                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6610                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6611                                                                                                                         player[k].rotation*=360/6.28;
6612                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6613                                                                                                                         player[k].targetrotation=player[k].rotation;
6614                                                                                                                         player[k].lowrotation=player[k].rotation;
6615                                                                                                                         if(k==0)numwallflipped++;
6616                                                                                                                 }
6617                                                                                                                 else
6618                                                                                                                 {
6619                                                                                                                         lowpoint=tempcoords1;
6620                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6621                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6622                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6623                                                                                                                                 player[k].target=0;
6624                                                                                                                                 player[k].targetanimation=walljumprightanim;
6625                                                                                                                                 player[k].targetframe=0;
6626                                                                                                                                 float gLoc[3];
6627                                                                                                                                 float vel[3];
6628                                                                                                                                 gLoc[0]=player[k].coords.x;
6629                                                                                                                                 gLoc[1]=player[k].coords.y;
6630                                                                                                                                 gLoc[2]=player[k].coords.z;
6631                                                                                                                                 vel[0]=0;
6632                                                                                                                                 vel[1]=0;
6633                                                                                                                                 vel[2]=0;
6634                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6635                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6636                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6637                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], false);
6638                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], true);
6639
6640                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6641                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6642                                                                                                                                 player[k].rotation*=360/6.28;
6643                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6644                                                                                                                                 player[k].targetrotation=player[k].rotation;
6645                                                                                                                                 player[k].lowrotation=player[k].rotation;
6646                                                                                                                                 if(k==0)numwallflipped++;
6647                                                                                                                         }
6648                                                                                                                         else
6649                                                                                                                         {
6650                                                                                                                                 lowpoint=tempcoords1;
6651                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6652                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6653                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6654                                                                                                                                         player[k].target=0;
6655                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6656                                                                                                                                         player[k].targetframe=0;
6657                                                                                                                                         float gLoc[3];
6658                                                                                                                                         float vel[3];
6659                                                                                                                                         gLoc[0]=player[k].coords.x;
6660                                                                                                                                         gLoc[1]=player[k].coords.y;
6661                                                                                                                                         gLoc[2]=player[k].coords.z;
6662                                                                                                                                         vel[0]=0;
6663                                                                                                                                         vel[1]=0;
6664                                                                                                                                         vel[2]=0;
6665                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6666                                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6667                                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6668                                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], false);
6669                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], true);
6670
6671                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6672                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6673                                                                                                                                         player[k].rotation*=360/6.28;
6674                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6675                                                                                                                                         player[k].targetrotation=player[k].rotation;
6676                                                                                                                                         player[k].lowrotation=player[k].rotation;
6677                                                                                                                                         if(k==0)numwallflipped++;
6678                                                                                                                                 }
6679                                                                                                                                 else
6680                                                                                                                                 {
6681                                                                                                                                         lowpoint=tempcoords1;
6682                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6683                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6684                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6685                                                                                                                                                 player[k].target=0;
6686                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6687                                                                                                                                                 player[k].targetframe=0;
6688                                                                                                                                                 float gLoc[3];
6689                                                                                                                                                 float vel[3];
6690                                                                                                                                                 gLoc[0]=player[k].coords.x;
6691                                                                                                                                                 gLoc[1]=player[k].coords.y;
6692                                                                                                                                                 gLoc[2]=player[k].coords.z;
6693                                                                                                                                                 vel[0]=0;
6694                                                                                                                                                 vel[1]=0;
6695                                                                                                                                                 vel[2]=0;
6696                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6697                                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6698                                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6699                                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], false);
6700                                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], true);
6701
6702                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6703                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6704                                                                                                                                                 player[k].rotation*=360/6.28;
6705                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6706                                                                                                                                                 player[k].rotation+=180;
6707                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6708                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6709                                                                                                                                                 if(k==0)numwallflipped++;
6710                                                                                                                                         }
6711                                                                                                                                 }
6712                                                                                                                         }
6713                                                                                                                 }
6714                                                                                                         }
6715                                                                                                 }
6716                                                                                         }
6717                                                                                         else if(objects.type[i]==rocktype){
6718                                                                                                 lowpoint2=player[k].coords;
6719                                                                                                 lowpoint=player[k].coords;
6720                                                                                                 lowpoint.y+=2;
6721                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6722                                                                                                         player[k].coords=colpoint;
6723                                                                                                         player[k].collide=1;
6724                                                                                                         tempcollide=1;
6725
6726                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6727                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6728
6729                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6730                                                                                                                 player[k].target=0;
6731                                                                                                                 player[k].targetframe=0;
6732                                                                                                                 player[k].onterrain=1;
6733
6734                                                                                                                 if(player[k].id==0){
6735                                                                                                                         FSOUND_SetPaused(channels[whooshsound], true);
6736                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 0);
6737                                                                                                                 }
6738
6739                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6740                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6741                                                                                                                         player[k].targetanimation=player[k].getLanding();
6742                                                                                                                         float gLoc[3];
6743                                                                                                                         float vel[3];
6744                                                                                                                         gLoc[0]=player[k].coords.x;
6745                                                                                                                         gLoc[1]=player[k].coords.y;
6746                                                                                                                         gLoc[2]=player[k].coords.z;
6747                                                                                                                         vel[0]=player[k].velocity.x;
6748                                                                                                                         vel[1]=player[k].velocity.y;
6749                                                                                                                         vel[2]=player[k].velocity.z;
6750                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6751                                                                                                                         FSOUND_3D_SetAttributes(channels[landsound], gLoc, vel);
6752                                                                                                                         FSOUND_SetVolume(channels[landsound], 128);
6753                                                                                                                         FSOUND_SetPaused(channels[landsound], false);
6754                                                                                                                         if(k==0){
6755                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6756                                                                                                                                 envsoundvol[numenvsounds]=16;
6757                                                                                                                                 envsoundlife[numenvsounds]=.4;
6758                                                                                                                                 numenvsounds++;
6759                                                                                                                         }
6760
6761                                                                                                                 }
6762                                                                                                         }
6763                                                                                                 }
6764                                                                                         }
6765                                                                                 }
6766                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6767                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6768                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6769                                                                                                 lowpoint=player[k].coords;
6770                                                                                                 lowpoint.y+=1.35;
6771                                                                                                 if(objects.type[i]!=rocktype)
6772                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6773                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
6774                                                                                                                 player[k].coords=lowpoint;
6775                                                                                                                 player[k].coords.y-=1.35;
6776                                                                                                                 player[k].collide=1;
6777
6778                                                                                                                 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)){
6779                                                                                                                         lowpoint=player[k].coords;
6780                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6781                                                                                                                         lowpoint=player[k].coords;
6782                                                                                                                         lowpoint.y+=.05;
6783                                                                                                                         facing=0;
6784                                                                                                                         facing.z=-1;
6785                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6786                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6787                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6788                                                                                                                         if(whichhit!=-1){
6789                                                                                                                                 lowpoint=player[k].coords;
6790                                                                                                                                 lowpoint.y+=.1;
6791                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6792                                                                                                                                 lowpoint2=lowpoint;
6793                                                                                                                                 lowpointtarget2=lowpointtarget;
6794                                                                                                                                 lowpoint3=lowpoint;
6795                                                                                                                                 lowpointtarget3=lowpointtarget;
6796                                                                                                                                 lowpoint4=lowpoint;
6797                                                                                                                                 lowpointtarget4=lowpointtarget;
6798                                                                                                                                 lowpoint5=lowpoint;
6799                                                                                                                                 lowpointtarget5=lowpointtarget;
6800                                                                                                                                 lowpoint6=lowpoint;
6801                                                                                                                                 lowpointtarget6=lowpointtarget;
6802                                                                                                                                 lowpoint7=lowpoint;
6803                                                                                                                                 lowpointtarget7=lowpoint;
6804                                                                                                                                 lowpoint2.x+=.1;
6805                                                                                                                                 lowpointtarget2.x+=.1;
6806                                                                                                                                 lowpoint3.z+=.1;
6807                                                                                                                                 lowpointtarget3.z+=.1;
6808                                                                                                                                 lowpoint4.x-=.1;
6809                                                                                                                                 lowpointtarget4.x-=.1;
6810                                                                                                                                 lowpoint5.z-=.1;
6811                                                                                                                                 lowpointtarget5.z-=.1;
6812                                                                                                                                 lowpoint6.y+=45/13;
6813                                                                                                                                 lowpointtarget6.y+=45/13;
6814                                                                                                                                 lowpointtarget6+=facing*.6;
6815                                                                                                                                 lowpointtarget7.y+=90/13;
6816                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6817                                                                                                                                 if(objects.friction[i]>.5)
6818                                                                                                                                         if(whichhit!=-1){
6819                                                                                                                                                 //if(k==0){
6820                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6821                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6822                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6823                                                                                                                                                                 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)
6824                                                                                                                                                                         for(j=0;j<45;j++){
6825                                                                                                                                                                                 lowpoint=player[k].coords;
6826                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6827                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6828                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6829                                                                                                                                                                                         if(j<=6){
6830                                                                                                                                                                                                 j=100;
6831                                                                                                                                                                                         }
6832                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6833                                                                                                                                                                                         j=100;
6834                                                                                                                                                                                         }*/
6835                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6836                                                                                                                                                                                                 j=100;
6837                                                                                                                                                                                         }
6838                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6839                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6840                                                                                                                                                                                                 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)*/){
6841                                                                                                                                                                                                         lowpoint=player[k].coords;
6842                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6843                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6844                                                                                                                                                                                                         flatfacing=player[k].coords;
6845                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6846                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6847                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6848
6849                                                                                                                                                                                                         if(j>10||!player[k].isRun()){
6850                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6851                                                                                                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], true);
6852                                                                                                                                                                                                                 }
6853                                                                                                                                                                                                                 float gLoc[3];
6854                                                                                                                                                                                                                 float vel[3];
6855                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6856                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6857                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6858                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6859                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6860                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6861                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
6862                                                                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6863                                                                                                                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
6864                                                                                                                                                                                                                 FSOUND_SetPaused(channels[jumpsound], false);
6865
6866                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6867                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6868                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6869                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6870                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6871                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6872
6873                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6874                                                                                                                                                                                                                 player[k].velocity=0;
6875
6876                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6877                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6878                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6879                                                                                                                                                                                                                         player[k].jumppower=0;
6880                                                                                                                                                                                                                         player[k].jumpclimb=1;
6881                                                                                                                                                                                                                 }
6882                                                                                                                                                                                                                 player[k].transspeed=6;
6883                                                                                                                                                                                                                 player[k].target=0;
6884
6885                                                                                                                                                                                                                 //player[k].currentframe=1;
6886                                                                                                                                                                                                                 player[k].targetframe=1;
6887                                                                                                                                                                                                                 if(j>25){
6888                                                                                                                                                                                                                         //player[k].currentframe=0;
6889                                                                                                                                                                                                                         player[k].targetframe=0;
6890                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6891                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6892                                                                                                                                                                                                                         player[k].jumppower=0;
6893                                                                                                                                                                                                                 }
6894                                                                                                                                                                                                         }
6895                                                                                                                                                                                                         j=100;
6896                                                                                                                                                                                                 }
6897                                                                                                                                                                                         }
6898                                                                                                                                                                                 }
6899                                                                                                                                                                         }
6900                                                                                                                                                                         //}
6901                                                                                                                                         }
6902                                                                                                                         }
6903                                                                                                                 }
6904                                                                                                         }
6905                                                                                         }
6906                                                                                         if(player[k].collide<=0){
6907                                                                                                 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()){
6908                                                                                                         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)){
6909                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6910                                                                                                                 player[k].targetanimation=jumpdownanim;
6911                                                                                                                 player[k].targetframe=0;
6912                                                                                                                 player[k].target=0;
6913
6914                                                                                                                 float gLoc[3];
6915                                                                                                                 float vel[3];
6916                                                                                                                 gLoc[0]=player[k].coords.x;
6917                                                                                                                 gLoc[1]=player[k].coords.y;
6918                                                                                                                 gLoc[2]=player[k].coords.z;
6919                                                                                                                 vel[0]=player[k].velocity.x;
6920                                                                                                                 vel[1]=player[k].velocity.y;
6921                                                                                                                 vel[2]=player[k].velocity.z;
6922                                                                                                                 if(k==0){
6923                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
6924                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6925                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
6926                                                                                                                         FSOUND_SetPaused(channels[whooshsound], false);
6927                                                                                                                 }
6928                                                                                                         }
6929                                                                                                         player[k].velocity.y+=gravity;
6930                                                                                                 }
6931                                                                                         }
6932                                                                 }
6933                                                         }
6934                                                         player[k].realoldcoords=player[k].coords;
6935                                                 }
6936
6937                                                 static XYZ oldviewer;
6938
6939                                                 if(indialogue==-1){
6940                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6941                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6942                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6943                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6944                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6945                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6946                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6947                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6948                                                 }
6949                                                 else
6950                                                 {
6951                                                         player[0].forwardkeydown=0;
6952                                                         player[0].leftkeydown=0;
6953                                                         player[0].backkeydown=0;
6954                                                         player[0].rightkeydown=0;
6955                                                         player[0].jumpkeydown=0;
6956                                                         player[0].crouchkeydown=0;
6957                                                         player[0].drawkeydown=0;
6958                                                         player[0].throwkeydown=0;
6959                                                 }
6960
6961                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6962
6963
6964                                                 static bool endkeydown;
6965                                                 if(indialogue!=-1){
6966                                                         cameramode=1;
6967                                                         if(directing){
6968                                                                 facing=0;
6969                                                                 facing.z=-1;
6970
6971                                                                 facing=DoRotation(facing,-rotation2,0,0);
6972                                                                 facing=DoRotation(facing,0,0-rotation,0);
6973
6974                                                                 flatfacing=0;
6975                                                                 flatfacing.z=-1;
6976
6977                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6978
6979                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6980                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6981                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6982                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6983                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6984                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6985                                                                 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)
6986                                                                         ||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)
6987                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6988                                                                                 int whichend;
6989                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6990                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6991                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6992                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6993                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6994                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6995                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6996                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6997                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6998                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6999                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
7000                                                                                 if(whichend!=-1){
7001                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
7002                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
7003                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
7004                                                                                 }
7005                                                                                 if(whichend==-1){
7006                                                                                         participantfocus[whichdialogue][indialogue]=-1;
7007                                                                                 }
7008                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
7009                                                                                         indialogue=-1;
7010                                                                                         directing=0;
7011                                                                                         cameramode=0;
7012                                                                                 }
7013                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
7014                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
7015                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
7016                                                                                 indialogue++;
7017                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
7018                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
7019                                                                                                 static float gLoc[3];
7020                                                                                                 static float vel[3];
7021                                                                                                 XYZ temppos;
7022                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7023                                                                                                 temppos=temppos-viewer;
7024                                                                                                 Normalise(&temppos);
7025                                                                                                 temppos+=viewer;
7026
7027                                                                                                 gLoc[0]=temppos.x;
7028                                                                                                 gLoc[1]=temppos.y;
7029                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
7030                                                                                                 vel[1]=0;
7031                                                                                                 vel[2]=0;
7032                                                                                                 int whichsoundplay;
7033                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7034                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7035                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7036                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7037                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7038                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7039                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7040                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7041                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7042                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7043                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7044                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7045                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7046                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7047                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7048                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7049                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7050                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7051                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7052                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7053                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
7054                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7055                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
7056                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], false);
7057                                                                                         }
7058                                                                                 }
7059
7060                                                                                 for(j=0;j<numplayers;j++){
7061                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
7062                                                                                 }
7063
7064                                                                                 endkeydown=1;
7065                                                                         }
7066                                                                         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)
7067                                                                                 ||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)
7068                                                                                 )){
7069                                                                                         int whichend;
7070                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
7071                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
7072                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
7073                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
7074                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
7075                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
7076                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
7077                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
7078                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
7079                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
7080                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
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                                                                                         }
7092                                                         }
7093                                                         if(!directing){
7094                                                                 FSOUND_SetPaused(channels[whooshsound], true);
7095                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
7096                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
7097                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
7098                                                                 }
7099                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
7100                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
7101                                                                 if(dialoguetime>0.5)
7102                                                                         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)
7103                                                                                 ||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)
7104                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
7105                                                                                         indialogue++;
7106                                                                                         endkeydown=1;
7107                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
7108                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
7109                                                                                                         static float gLoc[3];
7110                                                                                                         static float vel[3];
7111                                                                                                         XYZ temppos;
7112                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7113                                                                                                         temppos=temppos-viewer;
7114                                                                                                         Normalise(&temppos);
7115                                                                                                         temppos+=viewer;
7116
7117                                                                                                         gLoc[0]=temppos.x;
7118                                                                                                         gLoc[1]=temppos.y;
7119                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
7120                                                                                                         vel[1]=0;
7121                                                                                                         vel[2]=0;
7122                                                                                                         int whichsoundplay;
7123                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7124                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7125                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7126                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7127                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7128                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7129                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7130                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7131                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7132                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7133                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7134                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7135                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7136                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7137                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7138                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7139                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7140                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7141                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7142                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7143                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
7144                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
7145                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
7146                                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7147                                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
7148                                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], false);
7149                                                                                                         }
7150                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
7151                                                                                                                 hotspot[numhotspots]=player[0].coords;
7152                                                                                                                 hotspotsize[numhotspots]=10;
7153                                                                                                                 hotspottype[numhotspots]=-1;
7154
7155                                                                                                                 numhotspots++;
7156                                                                                                         }
7157                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
7158                                                                                                                 hostile=1;
7159                                                                                                         }
7160
7161                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
7162                                                                                                                 indialogue=-1;
7163                                                                                                                 directing=0;
7164                                                                                                                 cameramode=0;
7165                                                                                                         }
7166                                                                                                 }
7167                                                                                         }
7168                                                                                 }
7169                                                                                 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)
7170                                                                                         &&!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)
7171                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7172                                                                                                 endkeydown=0;
7173                                                                                         }
7174                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7175                                                                                                 indialogue=-1;
7176                                                                                                 directing=0;
7177                                                                                                 cameramode=0;
7178                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
7179                                                                                                         hostile=1;
7180                                                                                                 }
7181                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
7182                                                                                                         windialogue=1;
7183                                                                                                 }
7184                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
7185                                                                                                         hostile=1;
7186                                                                                                         for(i=1;i<numplayers;i++){
7187                                                                                                                 player[i].aitype = attacktypecutoff;
7188                                                                                                         }
7189                                                                                                 }
7190                                                                                         }
7191                                                         }
7192                                                 }
7193
7194                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
7195                                                 else oldbuttondialogue=1;
7196
7197                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
7198
7199                                                 //Net updates
7200
7201                                                 /*keyrefreshdelay-=multiplier;
7202                                                 bigrefreshdelay-=multiplier;
7203
7204                                                 if(keyrefreshdelay<=0){
7205                                                 static int concat[4];
7206
7207                                                 concat[0]=player[0].forwardkeydown;
7208                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
7209                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
7210                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
7211                                                 concat[0]=concat[0]*2+player[0].backkeydown;
7212                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
7213                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
7214                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
7215
7216                                                 concat[1]=player[0].crouchtogglekeydown;
7217                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
7218                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
7219                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
7220                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
7221                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
7222
7223                                                 //concat[2]=(char)((int)(rotation/2)%180);
7224
7225                                                 //concat[3]=(char)((int)(rotation2/2)%180);
7226
7227                                                 chatname[0]=concat[0]-128;
7228                                                 chatname[1]=concat[1]-128;
7229                                                 //chatname[2]=concat[2]-128;
7230                                                 //chatname[3]=concat[3]-128;
7231                                                 int temppoint=2;
7232                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
7233                                                 temppoint+=sizeof(float);
7234                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
7235                                                 temppoint+=sizeof(float);
7236
7237                                                 chatname[temppoint]='\0';
7238
7239                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
7240                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
7241                                                 //keyrefreshdelay=.01;
7242                                                 keyrefreshdelay=.03;
7243                                                 }
7244
7245                                                 if(bigrefreshdelay<=0){
7246                                                 for(i=0;i<1;i++){
7247                                                 /*int temppoint=0;
7248                                                 memcpy(chatname+temppoint,&i,sizeof(int));
7249                                                 temppoint+=sizeof(int);
7250                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
7251                                                 temppoint+=sizeof(float);
7252                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
7253                                                 temppoint+=sizeof(float);
7254                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
7255                                                 temppoint+=sizeof(float);
7256                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
7257                                                 temppoint+=sizeof(float);
7258                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
7259                                                 temppoint+=sizeof(float);
7260                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
7261                                                 temppoint+=sizeof(int);
7262                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
7263                                                 temppoint+=sizeof(int);
7264                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
7265                                                 temppoint+=sizeof(float);
7266                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
7267                                                 temppoint+=sizeof(float);
7268                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
7269                                                 temppoint+=sizeof(float);
7270                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
7271                                                 temppoint+=sizeof(int);
7272                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
7273                                                 temppoint+=sizeof(int);
7274                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
7275                                                 temppoint+=sizeof(float);
7276                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
7277                                                 temppoint+=sizeof(float);
7278                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
7279                                                 temppoint+=sizeof(float);
7280                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
7281                                                 temppoint+=sizeof(int);
7282                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
7283                                                 temppoint+=sizeof(int);
7284                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
7285                                                 temppoint+=sizeof(int);
7286                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
7287                                                 temppoint+=sizeof(int);
7288                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
7289                                                 temppoint+=sizeof(int);
7290                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
7291                                                 temppoint+=sizeof(int);
7292                                                 chatname[temppoint]='\0';
7293
7294                                                 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);
7295                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
7296                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
7297
7298                                                 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);
7299
7300                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
7301                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
7302                                                 }
7303                                                 //bigrefreshdelay=.02;
7304                                                 bigrefreshdelay=.1;
7305                                                 }
7306                                                 }*/
7307
7308                                                 if(!player[0].jumpkeydown){
7309                                                         player[0].jumptogglekeydown=0;
7310                                                 }
7311                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
7312
7313
7314                                                 dialoguetime+=multiplier;
7315                                                 skybox.cloudmove+=multiplier;
7316                                                 hawkrotation+=multiplier*25;
7317                                                 realhawkcoords=0;
7318                                                 realhawkcoords.x=25;
7319                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
7320                                                 hawkcalldelay-=multiplier/2;
7321
7322                                                 if(hawkcalldelay<=0)
7323                                                 {
7324                                                         static float gLoc[3];
7325                                                         static float vel[3];
7326                                                         gLoc[0]=realhawkcoords.x;
7327                                                         gLoc[1]=realhawkcoords.y;
7328                                                         gLoc[2]=realhawkcoords.z;
7329                                                         vel[0]=0;
7330                                                         vel[1]=0;
7331                                                         vel[2]=0;
7332                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, true);
7333                                                         FSOUND_3D_SetAttributes(channels[hawksound], gLoc, vel);
7334                                                         FSOUND_SetVolume(channels[hawksound], 128);
7335                                                         FSOUND_SetPaused(channels[hawksound], false);
7336
7337                                                         hawkcalldelay=16+abs(Random()%8);
7338                                                 }
7339                                                 static float temptexdetail;
7340
7341
7342                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7343                                                         player[0].damagetolerance=200000;
7344                                                         player[0].damage=0;
7345                                                         player[0].burnt=0;
7346                                                         player[0].permanentdamage=0;
7347                                                         player[0].superpermanentdamage=0;
7348                                                         /*
7349                                                         int whichchar;
7350                                                         whichchar = abs(Random()%7);
7351                                                         registrationname[whichchar]+=1;
7352                                                         */
7353                                                 }
7354
7355                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7356                                                         environment++;
7357                                                         if(environment>2)environment=0;
7358                                                         Setenvironment(environment);
7359
7360                                                         envtogglekeydown=1;
7361                                                 }
7362
7363
7364                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7365                                                         envtogglekeydown=0;
7366                                                 }
7367
7368                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7369                                                         cameramode=1-cameramode;
7370                                                         cameratogglekeydown=1;
7371                                                 }
7372
7373                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7374                                                         cameratogglekeydown=0;
7375                                                 }
7376
7377                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7378                                                         if(player[0].num_weapons>0){
7379                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7380                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7381                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7382                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7383                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7384                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7385                                                                         weapons.length[player[0].weaponids[0]]=.8;
7386                                                                 }
7387                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7388                                                                         weapons.mass[player[0].weaponids[0]]=2;
7389                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7390                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7391                                                                 }
7392
7393                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7394                                                                         weapons.mass[player[0].weaponids[0]]=1;
7395                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7396                                                                         weapons.length[player[0].weaponids[0]]=.25;
7397                                                                 }
7398                                                         }
7399
7400                                                         /*for(i=0;i<objects.numobjects;i++){
7401                                                         if(objects.type[i]==treeleavestype){
7402                                                         for(j=0;j<objects.numobjects;j++){
7403                                                         if(objects.type[j]==treetrunktype)
7404                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7405                                                         objects.scale[i]=objects.scale[j];
7406                                                         }
7407                                                         }
7408                                                         }*/
7409                                                         detailtogglekeydown=1;
7410                                                 }
7411
7412                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7413                                                         int closest=-1;
7414                                                         float closestdist=-1;
7415                                                         float distance;
7416                                                         if(numplayers>1)
7417                                                                 for(i=1;i<numplayers;i++){
7418                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7419                                                                         if(closestdist==-1||distance<closestdist){
7420                                                                                 closestdist=distance;
7421                                                                                 closest=i;
7422                                                                         }
7423                                                                 }
7424                                                                 if(closest!=-1){
7425                                                                         if(player[closest].num_weapons)
7426                                                                         {
7427                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7428                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7429                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7430                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7431                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7432                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7433                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7434                                                                                 }
7435                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7436                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7437                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7438                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7439                                                                                 }
7440                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7441                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7442                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7443                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7444                                                                                 }
7445                                                                         }
7446                                                                         if(!player[closest].num_weapons)
7447                                                                         {
7448                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7449                                                                                 weapons.owner[weapons.numweapons]=closest;
7450                                                                                 weapons.type[weapons.numweapons]=knife;
7451                                                                                 weapons.damage[weapons.numweapons]=0;
7452                                                                                 weapons.numweapons++;
7453                                                                                 player[closest].num_weapons=1;
7454                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7455                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7456                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7457                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7458                                                                                 }
7459                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7460                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7461                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7462                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7463                                                                                 }
7464                                                                         }
7465                                                                 }
7466                                                                 detailtogglekeydown=1;
7467                                                 }
7468
7469                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7470                                                         int closest=-1;
7471                                                         float closestdist=-1;
7472                                                         float distance;
7473                                                         if(numplayers>1)
7474                                                                 for(i=1;i<numplayers;i++){
7475                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7476                                                                         if(closestdist==-1||distance<closestdist){
7477                                                                                 closestdist=distance;
7478                                                                                 closest=i;
7479                                                                         }
7480                                                                 }
7481
7482                                                                 player[closest].rotation+=multiplier*50;
7483                                                                 player[closest].targetrotation=player[closest].rotation;
7484                                                 }
7485
7486
7487                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7488                                                         int closest=-1;
7489                                                         float closestdist=-1;
7490                                                         float distance;
7491                                                         if(numplayers>1)
7492                                                                 for(i=1;i<numplayers;i++){
7493                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7494                                                                         if(closestdist==-1||distance<closestdist){
7495                                                                                 closestdist=distance;
7496                                                                                 closest=i;
7497                                                                         }
7498                                                                 }
7499                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7500
7501                                                                 if(closest!=-1){
7502                                                                         player[closest].whichskin++;
7503                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7504                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7505
7506                                                                         if(player[closest].creature==rabbittype){
7507                                                                                 if(player[closest].whichskin==0){
7508                                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7509                                                                                 }
7510                                                                                 else if(player[closest].whichskin==1){
7511                                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7512                                                                                 }
7513                                                                                 else if(player[closest].whichskin==2){
7514                                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7515                                                                                 }
7516                                                                                 else if(player[closest].whichskin==3){
7517                                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7518                                                                                 }
7519                                                                                 else if(player[closest].whichskin==4){
7520                                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7521                                                                                 }
7522                                                                                 else if(player[closest].whichskin==5){
7523                                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7524                                                                                 }
7525                                                                                 else if(player[closest].whichskin==6){
7526                                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7527                                                                                 }
7528                                                                                 else if(player[closest].whichskin==7){
7529                                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7530                                                                                 }
7531                                                                                 else if(player[closest].whichskin==8){
7532                                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7533                                                                                 }
7534                                                                                 else if(player[closest].whichskin==9){
7535                                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7536                                                                                 }
7537                                                                         }
7538                                                                         if(player[closest].creature==wolftype){
7539                                                                                 k=abs(Random()%3);
7540                                                                                 if(player[closest].whichskin==0){
7541                                                                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7542                                                                                 }
7543                                                                                 else if(player[closest].whichskin==1){
7544                                                                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7545                                                                                 }
7546                                                                                 else if(player[closest].whichskin==2){
7547                                                                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7548                                                                                 }
7549                                                                         }
7550                                                                 }
7551
7552                                                                 if(player[closest].numclothes){
7553                                                                         for(i=0;i<player[closest].numclothes;i++){
7554                                                                                 tintr=player[closest].clothestintr[i];
7555                                                                                 tintg=player[closest].clothestintg[i];
7556                                                                                 tintb=player[closest].clothestintb[i];
7557                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7558                                                                         }
7559                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7560                                                                 }
7561
7562                                                                 detailtogglekeydown=1;
7563                                                 }
7564
7565                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7566                                                         int closest=-1;
7567                                                         float closestdist=-1;
7568                                                         float distance;
7569                                                         if(numplayers>1)
7570                                                                 for(i=1;i<numplayers;i++){
7571                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7572                                                                         if(closestdist==-1||distance<closestdist){
7573                                                                                 closestdist=distance;
7574                                                                                 closest=i;
7575                                                                         }
7576                                                                 }
7577                                                                 if(closest!=-1){
7578                                                                         if(player[closest].creature==wolftype){
7579                                                                                 headprop=player[closest].proportionhead.x/1.1;
7580                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7581                                                                                 armprop=player[closest].proportionarms.x/1.1;
7582                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7583                                                                         }
7584
7585                                                                         if(player[closest].creature==rabbittype){
7586                                                                                 headprop=player[closest].proportionhead.x/1.2;
7587                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7588                                                                                 armprop=player[closest].proportionarms.x/1.00;
7589                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7590                                                                         }
7591
7592
7593                                                                         if(player[closest].creature==rabbittype){
7594                                                                                 player[closest].skeleton.id=closest;
7595                                                                                 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);
7596                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7597                                                                                 player[closest].whichskin=0;
7598                                                                                 player[closest].creature=wolftype;
7599
7600                                                                                 player[closest].proportionhead=1.1;
7601                                                                                 player[closest].proportionbody=1.1;
7602                                                                                 player[closest].proportionarms=1.1;
7603                                                                                 player[closest].proportionlegs=1.1;
7604                                                                                 player[closest].proportionlegs.y=1.1;
7605                                                                                 player[closest].scale=.23*5*player[0].scale;
7606
7607                                                                                 player[closest].damagetolerance=300;
7608                                                                         }
7609                                                                         else
7610                                                                         {
7611                                                                                 player[closest].skeleton.id=closest;
7612                                                                                 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);
7613                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7614                                                                                 player[closest].whichskin=0;
7615                                                                                 player[closest].creature=rabbittype;
7616
7617                                                                                 player[closest].proportionhead=1.2;
7618                                                                                 player[closest].proportionbody=1.05;
7619                                                                                 player[closest].proportionarms=1.00;
7620                                                                                 player[closest].proportionlegs=1.1;
7621                                                                                 player[closest].proportionlegs.y=1.05;
7622                                                                                 player[closest].scale=.2*5*player[0].scale;
7623
7624                                                                                 player[closest].damagetolerance=200;
7625                                                                         }
7626
7627                                                                         if(player[closest].creature==wolftype){
7628                                                                                 player[closest].proportionhead=1.1*headprop;
7629                                                                                 player[closest].proportionbody=1.1*bodyprop;
7630                                                                                 player[closest].proportionarms=1.1*armprop;
7631                                                                                 player[closest].proportionlegs=1.1*legprop;
7632                                                                         }
7633
7634                                                                         if(player[closest].creature==rabbittype){
7635                                                                                 player[closest].proportionhead=1.2*headprop;
7636                                                                                 player[closest].proportionbody=1.05*bodyprop;
7637                                                                                 player[closest].proportionarms=1.00*armprop;
7638                                                                                 player[closest].proportionlegs=1.1*legprop;
7639                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7640                                                                         }
7641
7642                                                                 }
7643                                                                 detailtogglekeydown=1;
7644                                                 }
7645
7646                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7647                                                         detailtogglekeydown=0;
7648                                                 }
7649
7650                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7651                                                         slomo=1-slomo;
7652                                                         slomodelay=1000;
7653                                                         slomotogglekeydown=1;
7654                                                 }
7655
7656
7657                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7658                                                         int closest=-1;
7659                                                         float closestdist=-1;
7660                                                         float distance;
7661                                                         XYZ flatfacing2,flatvelocity2;
7662                                                         XYZ blah;
7663                                                         if(numplayers>1)
7664                                                                 for(i=1;i<numplayers;i++){
7665                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7666                                                                         if(distance<144&&!player[i].headless)
7667                                                                                 if(closestdist==-1||distance<closestdist){
7668                                                                                         closestdist=distance;
7669                                                                                         closest=i;
7670                                                                                         blah = player[i].coords;
7671                                                                                 }
7672                                                                 }
7673
7674                                                                 if(closest!=-1){
7675                                                                         XYZ headspurtdirection;
7676                                                                         int i = player[closest].skeleton.jointlabels[head];
7677                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7678                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7679                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7680                                                                                 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;
7681                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7682                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7683                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7684                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7685                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7686                                                                                 Normalise(&headspurtdirection);
7687                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7688                                                                                 flatvelocity2+=headspurtdirection*8;
7689                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7690                                                                         }
7691                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7692
7693                                                                         float gLoc[3];
7694                                                                         float vel[3];
7695                                                                         gLoc[0]=blah.x;
7696                                                                         gLoc[1]=blah.y;
7697                                                                         gLoc[2]=blah.z;
7698                                                                         vel[0]=0;
7699                                                                         vel[1]=0;
7700                                                                         vel[2]=0;
7701                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7702                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7703                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7704                                                                         FSOUND_SetPaused(channels[splattersound], false);
7705
7706                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7707                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7708                                                                         FSOUND_SetVolume(channels[breaksound2], 100);
7709                                                                         FSOUND_SetPaused(channels[breaksound2], false);
7710
7711                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7712                                                                         player[closest].RagDoll(0);
7713                                                                         player[closest].dead=2;
7714                                                                         player[closest].headless=1;
7715                                                                         player[closest].DoBloodBig(3,165);
7716
7717                                                                         camerashake+=.3;
7718                                                                 }
7719
7720                                                                 explodetogglekeydown=1;
7721                                                 }
7722
7723                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7724                                                         int closest=-1;
7725                                                         float closestdist=-1;
7726                                                         float distance;
7727                                                         XYZ flatfacing2,flatvelocity2;
7728                                                         XYZ blah;
7729                                                         if(numplayers>1)
7730                                                                 for(i=1;i<numplayers;i++){
7731                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7732                                                                         if(distance<144)
7733                                                                                 if(closestdist==-1||distance<closestdist){
7734                                                                                         closestdist=distance;
7735                                                                                         closest=i;
7736                                                                                         blah=player[i].coords;
7737                                                                                 }
7738                                                                 }
7739
7740                                                                 if(closest!=-1){
7741                                                                         float gLoc[3];
7742                                                                         float vel[3];
7743                                                                         gLoc[0]=blah.x;
7744                                                                         gLoc[1]=blah.y;
7745                                                                         gLoc[2]=blah.z;
7746                                                                         vel[0]=0;
7747                                                                         vel[1]=0;
7748                                                                         vel[2]=0;
7749
7750                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7751                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7752                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7753                                                                         FSOUND_SetPaused(channels[splattersound], false);
7754
7755                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7756                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7757                                                                         FSOUND_SetVolume(channels[breaksound2], 600);
7758                                                                         FSOUND_SetPaused(channels[breaksound2], false);
7759
7760                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7761                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7762                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7763                                                                                 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;
7764                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7765                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7766                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7767                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7768                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7769                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7770                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7771                                                                         }
7772
7773                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7774                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7775                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7776                                                                                 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;
7777                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7778                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7779                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7780                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7781                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7782                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7783                                                                         }
7784
7785                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7786                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7787                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7788                                                                                 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;
7789                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7790                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7791                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7792                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7793                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7794                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7795                                                                         }
7796
7797                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7798                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7799                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7800                                                                                 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;
7801                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7802                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7803                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7804                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7805                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7806                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7807                                                                         }
7808
7809                                                                         XYZ temppos;
7810                                                                         for(j=0;j<numplayers; j++){
7811                                                                                 if(j!=closest){
7812                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7813                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7814                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7815                                                                                                 player[j].skeleton.longdead=0;
7816                                                                                                 player[j].RagDoll(0);
7817                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7818                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7819                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7820                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7821                                                                                                                 Normalise(&flatvelocity2);
7822                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7823                                                                                                         }
7824                                                                                                 }
7825                                                                                         }
7826                                                                                 }
7827                                                                         }
7828
7829                                                                         player[closest].DoDamage(10000);
7830                                                                         player[closest].RagDoll(0);
7831                                                                         player[closest].dead=2;
7832                                                                         player[closest].coords=20;
7833                                                                         player[closest].skeleton.free=2;
7834
7835                                                                         camerashake+=.6;
7836
7837                                                                 }
7838
7839                                                                 explodetogglekeydown=1;
7840                                                 }
7841
7842                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7843                                                         explodetogglekeydown=0;
7844                                                 }
7845
7846                                                 /*
7847                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7848                                                 FILE                    *tfile;
7849                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7850                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7851                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7852                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7853                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7854                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7855                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7856
7857                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7858                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7859                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7860                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7861                                                 for(j=0;j<player[0].num_weapons;j++){
7862                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7863                                                 }
7864                                                 fwrite( &environment, 1, sizeof(int), tfile );
7865
7866                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7867                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7868                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7869                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7870                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7871
7872                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7873                                                 if(numplayers>1&&numplayers<maxplayers)
7874                                                 for(i=1;i<numplayers;i++){
7875                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7876                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7877                                                 for(j=0;j<player[i].num_weapons;j++){
7878                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7879                                                 }
7880                                                 if(player[i].numwaypoints<30){
7881                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7882                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7883                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7884                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7885                                                 }
7886                                                 else{
7887                                                 player[i].numwaypoints=0;
7888                                                 player[i].waypoint=0;
7889                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7890                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7891                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7892                                                 }
7893                                                 }
7894
7895                                                 fclose(tfile);
7896
7897                                                 slomotogglekeydown=1;
7898                                                 }*/
7899
7900                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7901                                                         slomotogglekeydown=0;
7902                                                 }
7903
7904
7905                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7906                                                         player[0].onfire=1-player[0].onfire;
7907                                                         if(player[0].onfire){
7908                                                                 player[0].CatchFire();
7909                                                         }
7910                                                         if(!player[0].onfire){
7911                                                                 float gLoc[3];
7912                                                                 float vel[3];
7913                                                                 gLoc[0]=player[0].coords.x;
7914                                                                 gLoc[1]=player[0].coords.y;
7915                                                                 gLoc[2]=player[0].coords.z;
7916                                                                 vel[0]=0;
7917                                                                 vel[1]=0;
7918                                                                 vel[2]=0;
7919                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7920                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7921                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
7922                                                                 FSOUND_SetPaused(channels[fireendsound], false);
7923                                                                 FSOUND_SetPaused(channels[stream_firesound], true);
7924                                                         }
7925                                                         slomotogglekeydown=1;
7926                                                 }
7927                                                 /*
7928                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7929                                                 if(player[0].bleeding<=0)
7930                                                 player[0].DoBlood(1,255);
7931                                                 }*/
7932
7933
7934                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7935                                                         int closest=-1;
7936                                                         float closestdist=-1;
7937                                                         float distance;
7938                                                         if(numplayers>1)
7939                                                                 for(i=1;i<numplayers;i++){
7940                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7941                                                                         if(closestdist==-1||distance<closestdist){
7942                                                                                 closestdist=distance;
7943                                                                                 closest=i;
7944                                                                         }
7945                                                                 }
7946                                                                 if(closestdist>0&&closest>=0){
7947                                                                         //player[closest]=player[numplayers-1];
7948                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7949                                                                         numplayers--;
7950                                                                 }
7951                                                                 drawmodetogglekeydown=1;
7952                                                 }
7953
7954                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7955                                                         int closest=-1;
7956                                                         float closestdist=-1;
7957                                                         float distance;
7958                                                         if(max_objects>1)
7959                                                                 for(i=1;i<max_objects;i++){
7960                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7961                                                                         if(closestdist==-1||distance<closestdist){
7962                                                                                 closestdist=distance;
7963                                                                                 closest=i;
7964                                                                         }
7965                                                                 }
7966                                                                 if(closestdist>0&&closest>=0){
7967                                                                         objects.position[closest].y-=500;
7968                                                                 }
7969                                                                 drawmodetogglekeydown=1;
7970                                                 }
7971
7972                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7973                                                         //drawmode++;
7974                                                         //if(drawmode>2)drawmode=0;
7975                                                         if(objects.numobjects<max_objects-1){
7976                                                                 XYZ boxcoords;
7977                                                                 boxcoords.x=player[0].coords.x;
7978                                                                 boxcoords.z=player[0].coords.z;
7979                                                                 boxcoords.y=player[0].coords.y-3;
7980                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7981                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7982                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7983                                                                 float temprotat,temprotat2;
7984                                                                 temprotat=editorrotation;
7985                                                                 temprotat2=editorrotation2;
7986                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7987                                                                 if(temprotat2<0)temprotat2=Random()%360;
7988
7989                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7990                                                                 if(editortype==treetrunktype)
7991                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7992                                                         }
7993
7994                                                         drawmodetogglekeydown=1;
7995                                                 }
7996
7997                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7998                                                         if(numplayers<maxplayers-1){
7999                                                                 player[numplayers].scale=.2*5*player[0].scale;
8000                                                                 player[numplayers].creature=rabbittype;
8001                                                                 player[numplayers].howactive=editoractive;
8002                                                                 player[numplayers].skeleton.id=numplayers;
8003                                                                 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);
8004
8005                                                                 //texsize=512*512*3/texdetail/texdetail;
8006                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
8007                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
8008
8009                                                                 k=abs(Random()%2)+1;
8010                                                                 if(k==0){
8011                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8012                                                                         player[numplayers].whichskin=0;
8013                                                                 }
8014                                                                 else if(k==1){
8015                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8016                                                                         player[numplayers].whichskin=1;
8017                                                                 }
8018                                                                 else {
8019                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8020                                                                         player[numplayers].whichskin=2;
8021                                                                 }
8022
8023                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
8024                                                                 player[numplayers].power=1;
8025                                                                 player[numplayers].speedmult=1;
8026                                                                 player[numplayers].currentanimation=bounceidleanim;
8027                                                                 player[numplayers].targetanimation=bounceidleanim;
8028                                                                 player[numplayers].currentframe=0;
8029                                                                 player[numplayers].targetframe=1;
8030                                                                 player[numplayers].target=0;
8031                                                                 player[numplayers].bled=0;
8032                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
8033
8034                                                                 player[numplayers].targetrotation=player[0].targetrotation;
8035                                                                 player[numplayers].rotation=player[0].rotation;
8036
8037                                                                 player[numplayers].velocity=0;
8038                                                                 player[numplayers].coords=player[0].coords;
8039                                                                 player[numplayers].oldcoords=player[numplayers].coords;
8040                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
8041
8042                                                                 player[numplayers].id=numplayers;
8043                                                                 player[numplayers].skeleton.id=numplayers;
8044                                                                 player[numplayers].updatedelay=0;
8045                                                                 player[numplayers].normalsupdatedelay=0;
8046
8047                                                                 player[numplayers].aitype=passivetype;
8048                                                                 player[numplayers].aitarget=0;
8049
8050                                                                 if(player[0].creature==wolftype){
8051                                                                         headprop=player[0].proportionhead.x/1.1;
8052                                                                         bodyprop=player[0].proportionbody.x/1.1;
8053                                                                         armprop=player[0].proportionarms.x/1.1;
8054                                                                         legprop=player[0].proportionlegs.x/1.1;
8055                                                                 }
8056
8057                                                                 if(player[0].creature==rabbittype){
8058                                                                         headprop=player[0].proportionhead.x/1.2;
8059                                                                         bodyprop=player[0].proportionbody.x/1.05;
8060                                                                         armprop=player[0].proportionarms.x/1.00;
8061                                                                         legprop=player[0].proportionlegs.x/1.1;
8062                                                                 }
8063
8064                                                                 if(player[numplayers].creature==wolftype){
8065                                                                         player[numplayers].proportionhead=1.1*headprop;
8066                                                                         player[numplayers].proportionbody=1.1*bodyprop;
8067                                                                         player[numplayers].proportionarms=1.1*armprop;
8068                                                                         player[numplayers].proportionlegs=1.1*legprop;
8069                                                                 }
8070
8071                                                                 if(player[numplayers].creature==rabbittype){
8072                                                                         player[numplayers].proportionhead=1.2*headprop;
8073                                                                         player[numplayers].proportionbody=1.05*bodyprop;
8074                                                                         player[numplayers].proportionarms=1.00*armprop;
8075                                                                         player[numplayers].proportionlegs=1.1*legprop;
8076                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
8077                                                                 }
8078
8079                                                                 player[numplayers].headless=0;
8080                                                                 player[numplayers].onfire=0;
8081
8082                                                                 if(cellophane){
8083                                                                         player[numplayers].proportionhead.z=0;
8084                                                                         player[numplayers].proportionbody.z=0;
8085                                                                         player[numplayers].proportionarms.z=0;
8086                                                                         player[numplayers].proportionlegs.z=0;
8087                                                                 }
8088
8089                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
8090
8091                                                                 player[numplayers].damagetolerance=200;
8092
8093                                                                 player[numplayers].protectionhead=player[0].protectionhead;
8094                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
8095                                                                 player[numplayers].protectionlow=player[0].protectionlow;
8096                                                                 player[numplayers].armorhead=player[0].armorhead;
8097                                                                 player[numplayers].armorhigh=player[0].armorhigh;
8098                                                                 player[numplayers].armorlow=player[0].armorlow;
8099                                                                 player[numplayers].metalhead=player[0].metalhead;
8100                                                                 player[numplayers].metalhigh=player[0].metalhigh;
8101                                                                 player[numplayers].metallow=player[0].metallow;
8102
8103                                                                 player[numplayers].immobile=player[0].immobile;
8104
8105                                                                 player[numplayers].numclothes=player[0].numclothes;
8106                                                                 if(player[numplayers].numclothes)
8107                                                                         for(i=0;i<player[numplayers].numclothes;i++){
8108                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
8109                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
8110                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
8111                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
8112                                                                                 tintr=player[numplayers].clothestintr[i];
8113                                                                                 tintg=player[numplayers].clothestintg[i];
8114                                                                                 tintb=player[numplayers].clothestintb[i];
8115                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8116                                                                         }
8117                                                                         if(player[numplayers].numclothes){
8118                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
8119                                                                         }
8120
8121                                                                         player[numplayers].power=player[0].power;
8122                                                                         player[numplayers].speedmult=player[0].speedmult;
8123
8124                                                                         player[numplayers].damage=0;
8125                                                                         player[numplayers].permanentdamage=0;
8126                                                                         player[numplayers].superpermanentdamage=0;
8127                                                                         player[numplayers].deathbleeding=0;
8128                                                                         player[numplayers].bleeding=0;
8129                                                                         player[numplayers].numwaypoints=0;
8130                                                                         player[numplayers].waypoint=0;
8131                                                                         player[numplayers].jumppath=0;
8132                                                                         player[numplayers].weaponstuck=-1;
8133                                                                         player[numplayers].weaponactive=-1;
8134                                                                         player[numplayers].num_weapons=0;
8135                                                                         player[numplayers].bloodloss=0;
8136                                                                         player[numplayers].dead=0;
8137
8138                                                                         player[numplayers].loaded=1;
8139
8140                                                                         numplayers++;
8141                                                         }
8142                                                         drawmodetogglekeydown=1;
8143                                                 }
8144
8145                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
8146                                                         if(player[numplayers-1].numwaypoints<90){
8147                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
8148                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
8149                                                                 player[numplayers-1].numwaypoints++;
8150                                                         }
8151                                                         drawmodetogglekeydown=1;
8152                                                 }
8153
8154                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
8155                                                         if(numpathpoints<30){
8156                                                                 bool connected,alreadyconnected;
8157                                                                 connected=0;
8158                                                                 if(numpathpoints>1)
8159                                                                         for(i=0;i<numpathpoints;i++){
8160                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
8161                                                                                         alreadyconnected=0;
8162                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
8163                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
8164                                                                                         }
8165                                                                                         if(!alreadyconnected){
8166                                                                                                 numpathpointconnect[pathpointselected]++;
8167                                                                                                 connected=1;
8168                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
8169                                                                                         }
8170                                                                                 }
8171                                                                         }
8172                                                                         if(!connected){
8173                                                                                 numpathpoints++;
8174                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
8175                                                                                 numpathpointconnect[numpathpoints-1]=0;
8176                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
8177                                                                                         numpathpointconnect[pathpointselected]++;
8178                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
8179                                                                                 }
8180                                                                                 pathpointselected=numpathpoints-1;
8181                                                                         }
8182                                                         }
8183                                                         drawmodetogglekeydown=1;
8184                                                 }
8185
8186                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
8187                                                         pathpointselected++;
8188                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
8189                                                         drawmodetogglekeydown=1;
8190                                                 }
8191                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8192                                                         pathpointselected--;
8193                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
8194                                                         drawmodetogglekeydown=1;
8195                                                 }
8196                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8197                                                         if(pathpointselected!=-1){
8198                                                                 numpathpoints--;
8199                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
8200                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
8201                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
8202                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
8203                                                                 }
8204                                                                 for(i=0;i<numpathpoints;i++){
8205                                                                         for(j=0;j<numpathpointconnect[i];j++){
8206                                                                                 if(pathpointconnect[i][j]==pathpointselected){
8207                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
8208                                                                                         numpathpointconnect[i]--;
8209                                                                                 }
8210                                                                                 if(pathpointconnect[i][j]==numpathpoints){
8211                                                                                         pathpointconnect[i][j]=pathpointselected;
8212                                                                                 }
8213                                                                         }
8214                                                                 }
8215                                                                 pathpointselected=numpathpoints-1;
8216                                                         }
8217                                                         drawmodetogglekeydown=1;
8218                                                 }
8219
8220                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
8221                                                         editorenabled=1-editorenabled;
8222                                                         if(editorenabled){
8223                                                                 player[0].damagetolerance=100000;
8224                                                                 player[0].damage=0;
8225                                                                 player[0].superpermanentdamage=0;
8226                                                                 player[0].bloodloss=0;
8227                                                                 player[0].deathbleeding=0;
8228                                                         }
8229                                                         if(!editorenabled){
8230                                                                 player[0].damagetolerance=200;
8231                                                                 player[0].damage=0;
8232                                                                 player[0].permanentdamage=0;
8233                                                                 player[0].superpermanentdamage=0;
8234                                                                 player[0].bloodloss=0;
8235                                                                 player[0].deathbleeding=0;
8236                                                         }
8237                                                         drawmodetogglekeydown=1;
8238                                                 }
8239
8240                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8241                                                         editortype--;
8242                                                         if(editortype==treeleavestype||editortype==10)editortype--;
8243                                                         if(editortype<0)editortype=firetype;
8244                                                         drawmodetogglekeydown=1;
8245                                                 }
8246
8247                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8248                                                         editortype++;
8249                                                         if(editortype==treeleavestype||editortype==10)editortype++;
8250                                                         if(editortype>firetype)editortype=0;
8251                                                         drawmodetogglekeydown=1;
8252                                                 }
8253
8254                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8255                                                         editorrotation-=multiplier*100;
8256                                                         if(editorrotation<-.01)editorrotation=-.01;
8257                                                         drawmodetogglekeydown=1;
8258                                                 }
8259
8260                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8261                                                         editorrotation+=multiplier*100;
8262                                                         drawmodetogglekeydown=1;
8263                                                 }
8264
8265                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8266                                                         editorsize+=multiplier;
8267                                                         drawmodetogglekeydown=1;
8268                                                 }
8269
8270                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8271                                                         editorsize-=multiplier;
8272                                                         if(editorsize<.1)editorsize=.1;
8273                                                         drawmodetogglekeydown=1;
8274                                                 }
8275
8276
8277                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8278                                                         mapradius-=multiplier*10;
8279                                                 }
8280
8281                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8282                                                         mapradius+=multiplier*10;
8283                                                 }
8284                                                 /*
8285                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8286                                                 mapcenter.x+=multiplier*20;
8287                                                 }
8288
8289                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8290                                                 mapcenter.x-=multiplier*20;
8291                                                 }
8292
8293                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8294                                                 mapcenter.z+=multiplier*20;
8295                                                 }
8296
8297                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8298                                                 mapcenter.z-=multiplier*20;
8299                                                 }
8300                                                 */
8301                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8302                                                         editorrotation2+=multiplier*100;
8303                                                 }
8304
8305                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8306                                                         editorrotation2-=multiplier*100;
8307                                                         if(editorrotation2<-.01)editorrotation2=-.01;
8308                                                 }
8309                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
8310                                                         int closest=-1;
8311                                                         float closestdist=-1;
8312                                                         float distance;
8313                                                         for(i=0;i<objects.numobjects;i++){
8314                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
8315                                                                 if(closestdist==-1||distance<closestdist){
8316                                                                         closestdist=distance;
8317                                                                         closest=i;
8318                                                                 }
8319                                                         }
8320                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
8321                                                         drawmodetogglekeydown=1;
8322                                                 }
8323
8324
8325                                                 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)){
8326                                                         drawmodetogglekeydown=0;
8327                                                 }
8328
8329                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8330                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8331                                                         player[0].RagDoll(0);
8332                                                         //player[0].spurt=1;
8333                                                         //player[0].DoDamage(1000);
8334
8335                                                         float gLoc[3];
8336                                                         float vel[3];
8337                                                         gLoc[0]=player[0].coords.x;
8338                                                         gLoc[1]=player[0].coords.y;
8339                                                         gLoc[2]=player[0].coords.z;
8340                                                         vel[0]=player[0].velocity.x;
8341                                                         vel[1]=player[0].velocity.y;
8342                                                         vel[2]=player[0].velocity.z;
8343                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
8344                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8345                                                         FSOUND_SetVolume(channels[whooshsound], 128);
8346                                                         FSOUND_SetPaused(channels[whooshsound], false);
8347                                                         //FSOUND_SetPaused(channels[whooshsound], true);
8348
8349                                                         texturesizetogglekeydown=1;
8350                                                 }
8351
8352                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8353
8354                                                         int closest=-1;
8355                                                         float closestdist=-1;
8356                                                         float distance;
8357                                                         for(i=0;i<objects.numobjects;i++){
8358                                                                 if(objects.type[i]==treeleavestype){
8359                                                                         objects.scale[i]*=.9;
8360                                                                 }
8361                                                         }
8362                                                         texturesizetogglekeydown=1;
8363                                                 }
8364
8365                                                 static XYZ relative;
8366                                                 static int randattack;
8367                                                 //Attack
8368                                                 static bool playerrealattackkeydown=0;
8369
8370                                                 if(!buttons[0])oldbutton=0;
8371                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8372                                                 if(oldattackkey)player[0].attackkeydown=0;
8373                                                 if(oldattackkey)playerrealattackkeydown=0;
8374                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8375                                                 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);
8376                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8377                                                         for(k=0;k<numplayers;k++){
8378                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8379                                                                         player[k].Reverse();
8380                                                         }
8381                                                 }
8382
8383                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8384
8385                                                 for(k=0;k<numplayers;k++){
8386                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8387                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8388                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
8389                                                                 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)){
8390                                                                         player[k].jumppower-=2;
8391                                                                 }
8392                                                                 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)){
8393                                                                         for(i=0;i<numplayers;i++){
8394                                                                                 if(i==k)i++;
8395                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8396                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8397                                                                                                 player[k].targetanimation=dodgebackanim;
8398                                                                                                 player[k].target=0;
8399                                                                                                 player[k].targetframe=0;
8400                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8401                                                                                                 Normalise(&rotatetarget);
8402                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8403                                                                                                 player[k].targetrotation*=360/6.28;
8404                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8405
8406                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8407                                                                                         }
8408                                                                         }
8409                                                                         if(player[k].targetanimation!=dodgebackanim){
8410                                                                                 if(k==0)numflipped++;
8411                                                                                 player[k].targetanimation=backhandspringanim;
8412                                                                                 player[k].target=0;
8413                                                                                 player[k].targetframe=0;
8414                                                                                 player[k].targetrotation=-rotation+180;
8415                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8416                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8417                                                                                 player[k].rotation=player[k].targetrotation;
8418                                                                                 player[k].jumppower-=2;
8419                                                                         }
8420                                                                 }
8421                                                                 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())){
8422                                                                         player[k].hasvictim=0;
8423                                                                         if(numplayers>1)
8424                                                                                 for(i=0;i<numplayers;i++){
8425                                                                                         if(i==k)i++;
8426                                                                                         if(!player[k].hasvictim)
8427                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
8428                                                                                                         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){
8429                                                                                                                 player[k].victim=&player[i];
8430                                                                                                                 player[k].hasvictim=1;
8431                                                                                                                 if(player[k].aitype==playercontrolled){
8432                                                                                                                         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;
8433                                                                                                                         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;
8434                                                                                                                         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;
8435                                                                                                                         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;
8436                                                                                                                         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;
8437                                                                                                                         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;
8438                                                                                                                         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;
8439                                                                                                                         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;
8440                                                                                                                         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;
8441                                                                                                                         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;
8442                                                                                                                 }
8443                                                                                                                 else {
8444                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8445                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8446                                                                                                                                 else randattack=abs(Random()%5);
8447                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8448                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8449                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8450                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8451                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8452                                                                                                                                 }
8453                                                                                                                                 if(player[k].weaponactive!=-1){
8454                                                                                                                                         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;
8455                                                                                                                                         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;
8456                                                                                                                                         //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;
8457                                                                                                                                         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;
8458                                                                                                                                         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;
8459                                                                                                                                         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;
8460                                                                                                                                         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;
8461                                                                                                                                         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;
8462                                                                                                                                 }
8463                                                                                                                         }
8464                                                                                                                 }
8465                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8466                                                                                                         }
8467                                                                                                         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)){
8468                                                                                                                 if(player[k].weaponactive==-1){
8469                                                                                                                         player[i].targetanimation=sneakattackedanim;
8470                                                                                                                         player[i].currentanimation=sneakattackedanim;
8471                                                                                                                         player[k].currentanimation=sneakattackanim;
8472                                                                                                                         player[k].targetanimation=sneakattackanim;
8473                                                                                                                         player[k].oldcoords=player[k].coords;
8474                                                                                                                         player[k].coords=player[i].coords;
8475                                                                                                                 }
8476                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8477                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8478                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8479                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8480                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8481                                                                                                                         player[i].oldcoords=player[i].coords;
8482                                                                                                                         player[i].coords=player[k].coords;
8483                                                                                                                 }
8484                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8485                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8486                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8487                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8488                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8489                                                                                                                         player[i].oldcoords=player[i].coords;
8490                                                                                                                         player[i].coords=player[k].coords;
8491                                                                                                                 }
8492                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8493                                                                                                                         player[k].victim=&player[i];
8494                                                                                                                         player[k].hasvictim=1;
8495                                                                                                                         player[i].targettilt2=0;
8496                                                                                                                         player[i].targetframe=1;
8497                                                                                                                         player[i].currentframe=0;
8498                                                                                                                         player[i].target=0;
8499                                                                                                                         player[i].velocity=0;
8500                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8501                                                                                                                         player[k].currentframe=player[i].currentframe;
8502                                                                                                                         player[k].targetframe=player[i].targetframe;
8503                                                                                                                         player[k].target=player[i].target;
8504                                                                                                                         player[k].velocity=0;
8505                                                                                                                         player[k].targetrotation=player[i].rotation;
8506                                                                                                                         player[k].rotation=player[i].rotation;
8507                                                                                                                         player[i].targetrotation=player[i].rotation;
8508                                                                                                                 }
8509                                                                                                         }
8510                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8511                                                                                                                 oldattackkey=1;
8512                                                                                                                 player[k].targetframe=0;
8513                                                                                                                 player[k].target=0;
8514                                                                                                                 //player[k].velocity=0;
8515
8516                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8517                                                                                                                 Normalise(&rotatetarget);
8518                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8519                                                                                                                 player[k].targetrotation*=360/6.28;
8520                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8521
8522                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8523
8524                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8525                                                                                                                 player[k].lastattack2=player[k].lastattack;
8526                                                                                                                 player[k].lastattack=player[k].targetanimation;
8527                                                                                                                 //player[k].targettilt2=0;
8528                                                                                                                 //slomo=1;
8529                                                                                                                 //slomodelay=.2;
8530                                                                                                         }
8531                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8532                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8533                                                                                                                 Normalise(&rotatetarget);
8534                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8535                                                                                                                 player[k].targetrotation*=360/6.28;
8536                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8537                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8538                                                                                                                 oldattackkey=1;
8539                                                                                                                 player[k].victim=&player[i];
8540                                                                                                                 player[k].hasvictim=1;
8541                                                                                                                 player[i].targetanimation=knifefollowedanim;
8542                                                                                                                 player[i].currentanimation=knifefollowedanim;
8543                                                                                                                 player[i].targettilt2=0;
8544                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8545                                                                                                                 player[i].targetframe=1;
8546                                                                                                                 player[i].currentframe=0;
8547                                                                                                                 player[i].target=0;
8548                                                                                                                 player[i].velocity=0;
8549                                                                                                                 player[k].currentanimation=knifefollowanim;
8550                                                                                                                 player[k].targetanimation=knifefollowanim;
8551                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8552                                                                                                                 player[k].currentframe=player[i].currentframe;
8553                                                                                                                 player[k].targetframe=player[i].targetframe;
8554                                                                                                                 player[k].target=player[i].target;
8555                                                                                                                 player[k].velocity=0;
8556                                                                                                                 player[k].oldcoords=player[k].coords;
8557                                                                                                                 player[i].coords=player[k].coords;
8558                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8559                                                                                                                 player[i].rotation=player[k].targetrotation;
8560                                                                                                                 player[k].rotation=player[k].targetrotation;
8561                                                                                                                 player[i].rotation=player[k].targetrotation;
8562                                                                                                         }
8563                                                                                                 }
8564                                                                                 }
8565                                                                                 bool hasstaff=0;
8566                                                                                 if(player[k].weaponactive!=-1){
8567                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8568                                                                                 }
8569                                                                                 if(numplayers>1)
8570                                                                                         for(i=0;i<numplayers;i++){
8571                                                                                                 if(i==k)i++;
8572                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
8573                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8574                                                                                                                 if(player[i].skeleton.free)
8575                                                                                                                         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)))){
8576                                                                                                                                 player[k].victim=&player[i];
8577                                                                                                                                 player[k].hasvictim=1;
8578                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8579                                                                                                                                         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;
8580                                                                                                                                         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;
8581                                                                                                                                         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;
8582                                                                                                                                 }
8583                                                                                                                                 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){
8584                                                                                                                                         player[k].targetanimation=killanim;
8585                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8586                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8587                                                                                                                                                         terrain.DeleteDecal(j);
8588                                                                                                                                                 }
8589                                                                                                                                         }
8590                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8591                                                                                                                                                 if(objects.model[l].type==decalstype)
8592                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8593                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8594                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8595                                                                                                                                                                 }
8596                                                                                                                                                         }
8597                                                                                                                                         }
8598                                                                                                                                 }
8599                                                                                                                                 if(!player[i].dead||musictype!=2)
8600                                                                                                                                         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)){
8601                                                                                                                                                 player[k].targetanimation=dropkickanim;
8602                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8603                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8604                                                                                                                                                                 terrain.DeleteDecal(j);
8605                                                                                                                                                         }
8606                                                                                                                                                 }
8607                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8608                                                                                                                                                         if(objects.model[l].type==decalstype)
8609                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8610                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8611                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8612                                                                                                                                                                         }
8613                                                                                                                                                                 }
8614                                                                                                                                                 }
8615                                                                                                                                         }
8616                                                                                                                         }
8617                                                                                                                         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)){
8618                                                                                                                                 oldattackkey=1;
8619                                                                                                                                 player[k].targetframe=0;
8620                                                                                                                                 player[k].target=0;
8621                                                                                                                                 //player[k].velocity=0;
8622
8623                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8624                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8625                                                                                                                                         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;
8626                                                                                                                                 }
8627                                                                                                                                 Normalise(&rotatetarget);
8628                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8629                                                                                                                                 player[k].targetrotation*=360/6.28;
8630                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8631
8632                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8633                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8634                                                                                                                                 }
8635
8636                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8637                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8638
8639                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8640                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8641                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8642
8643                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8644                                                                                                                                         player[k].targetrotation+=30;
8645                                                                                                                                 }
8646                                                                                                                                 //player[k].targettilt2=0;
8647                                                                                                                                 //slomo=1;
8648                                                                                                                                 //slomodelay=.2;
8649                                                                                                                         }
8650                                                                                                 }
8651                                                                                         }
8652                                                                                         if(!player[k].hasvictim){
8653                                                                                                 for(i=0;i<numplayers;i++){
8654                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8655                                                                                                                 player[k].victim=&player[i];
8656                                                                                                                 player[k].hasvictim=1;
8657                                                                                                         }
8658                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8659                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8660                                                                                                                         player[k].victim=&player[i];
8661                                                                                                                 }
8662                                                                                                 }
8663                                                                                         }
8664                                                                                         if(player[k].aitype==playercontrolled)
8665                                                                                                 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)){
8666                                                                                                         oldattackkey=1;
8667                                                                                                         player[k].targetanimation=rabbitkickanim;
8668                                                                                                         player[k].targetframe=0;
8669                                                                                                         player[k].target=0;
8670                                                                                                 }
8671                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8672                                                                                                         numattacks++;
8673                                                                                                         bool armedstaff=0;
8674                                                                                                         if(player[k].weaponactive!=-1){
8675                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8676                                                                                                         }
8677                                                                                                         bool armedsword=0;
8678                                                                                                         if(player[k].weaponactive!=-1){
8679                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8680                                                                                                         }
8681                                                                                                         bool armedknife=0;
8682                                                                                                         if(player[k].weaponactive!=-1){
8683                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8684                                                                                                         }
8685                                                                                                         if(armedstaff)numstaffattack++;
8686                                                                                                         else if(armedsword)numswordattack++;
8687                                                                                                         else if(armedknife)numknifeattack++;
8688                                                                                                         else numunarmedattack++;
8689                                                                                                 }
8690                                                                 }
8691                                                         }
8692                                                 }
8693
8694                                                 //Collisions
8695                                                 static float collisionradius;
8696                                                 if(numplayers>1)
8697                                                         for(k=0;k<numplayers;k++){
8698                                                                 for(i=k;i<numplayers;i++){
8699                                                                         if(i==k)i++;
8700                                                                         if(i<numplayers)
8701                                                                                 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))
8702                                                                                         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))
8703                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8704                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8705                                                                                                                 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)
8706                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8707                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8708                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8709                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8710                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8711                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8712                                                                                                                                                                         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)){
8713                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8714                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8715                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8716                                                                                                                                                                                 }
8717                                                                                                                                                                         }
8718
8719                                                                                                                                                                         tempcoords1=player[i].coords;
8720                                                                                                                                                                         tempcoords2=player[k].coords;
8721                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8722                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8723                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8724                                                                                                                                                                         if(player[0].hasvictim)
8725                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8726                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
8727                                                                                                                                                                                 if(k==0)
8728                                                                                                                                                                                         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)){
8729                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8730                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8731                                                                                                                                                                                                 player[i].skeleton.free=0;
8732                                                                                                                                                                                                 player[i].rotation=0;
8733                                                                                                                                                                                                 player[i].RagDoll(0);
8734                                                                                                                                                                                                 player[i].DoDamage(20);
8735                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8736                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8737                                                                                                                                                                                                 player[k].lastcollide=1;
8738                                                                                                                                                                                         }
8739                                                                                                                                                                                         if(i==0)
8740                                                                                                                                                                                                 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)){
8741                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8742                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8743                                                                                                                                                                                                         player[k].skeleton.free=0;
8744                                                                                                                                                                                                         player[k].rotation=0;
8745                                                                                                                                                                                                         player[k].RagDoll(0);
8746                                                                                                                                                                                                         player[k].DoDamage(20);
8747                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8748                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8749                                                                                                                                                                                                         player[i].lastcollide=1;
8750                                                                                                                                                                                                 }
8751
8752                                                                                                                                                                                                 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)){
8753                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8754                                                                                                                                                                                                         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))
8755                                                                                                                                                                                                                 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))){
8756                                                                                                                                                                                                                         //If hit by body
8757                                                                                                                                                                                                                         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)){
8758                                                                                                                                                                                                                                 static float gLoc[3];
8759                                                                                                                                                                                                                                 static float vel[3];
8760                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8761                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8762                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8763                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8764                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8765                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8766                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8767                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
8768                                                                                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8769                                                                                                                                                                                                                                         FSOUND_SetVolume(channels[heavyimpactsound], 256);
8770                                                                                                                                                                                                                                         FSOUND_SetPaused(channels[heavyimpactsound], false);
8771                                                                                                                                                                                                                                 }
8772                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8773                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8774
8775                                                                                                                                                                                                                                 player[i].RagDoll(0);
8776                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8777                                                                                                                                                                                                                                         bonus=aimbonus;
8778                                                                                                                                                                                                                                         bonustime=0;
8779                                                                                                                                                                                                                                         bonusvalue=150;
8780                                                                                                                                                                                                                                 }
8781                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8782                                                                                                                                                                                                                                 player[k].RagDoll(0);
8783                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8784                                                                                                                                                                                                                                         bonus=aimbonus;
8785                                                                                                                                                                                                                                         bonustime=0;
8786                                                                                                                                                                                                                                         bonusvalue=150;
8787                                                                                                                                                                                                                                 }
8788                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8789
8790                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8791                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8792                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8793                                                                                                                                                                                                                                 }
8794                                                                                                                                                                                                                                 //}
8795                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8796                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8797                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8798                                                                                                                                                                                                                                 }
8799                                                                                                                                                                                                                                 //}
8800
8801                                                                                                                                                                                                                         }
8802                                                                                                                                                                                                                 }
8803                                                                                                                                                                                                                 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)){
8804                                                                                                                                                                                                                         //If bumped
8805                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8806                                                                                                                                                                                                                                 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)){
8807                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8808                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8809                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8810                                                                                                                                                                                                                                         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);
8811                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8812                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8813                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8814                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8815                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8816                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8817                                                                                                                                                                                                                                                                 player[k].target=0;
8818                                                                                                                                                                                                                                                         }
8819                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8820                                                                                                                                                                                                                                                         {
8821                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8822                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8823                                                                                                                                                                                                                                                                 player[k].target=0;
8824                                                                                                                                                                                                                                                         }
8825                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8826                                                                                                                                                                                                                                                 }
8827                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8828                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8829                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8830                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8831                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8832                                                                                                                                                                                                                                                                         player[i].target=0;
8833                                                                                                                                                                                                                                                                 }
8834                                                                                                                                                                                                                                                                 else
8835                                                                                                                                                                                                                                                                 {
8836                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8837                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8838                                                                                                                                                                                                                                                                         player[i].target=0;
8839                                                                                                                                                                                                                                                                 }
8840                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8841                                                                                                                                                                                                                                                         }
8842                                                                                                                                                                                                                                 }
8843                                                                                                                                                                                                                                 if(hostile){
8844                                                                                                                                                                                                                                         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){
8845                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8846                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8847                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8848                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8849                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8850                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8851                                                                                                                                                                                                                                                 player[k].lastcollide=1;
8852                                                                                                                                                                                                                                                 if(k==0){
8853                                                                                                                                                                                                                                                         bonus=AboveBonus;
8854                                                                                                                                                                                                                                                         bonustime=0;
8855                                                                                                                                                                                                                                                         bonusvalue=50;
8856                                                                                                                                                                                                                                                 }
8857                                                                                                                                                                                                                                         }
8858                                                                                                                                                                                                                                         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){
8859                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8860                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8861                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8862                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8863                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8864                                                                                                                                                                                                                                                 player[k].RagDoll(0);
8865                                                                                                                                                                                                                                                 player[i].lastcollide=1;
8866                                                                                                                                                                                                                                                 if(i==0){
8867                                                                                                                                                                                                                                                         bonus=AboveBonus;
8868                                                                                                                                                                                                                                                         bonustime=0;
8869                                                                                                                                                                                                                                                         bonusvalue=50;
8870                                                                                                                                                                                                                                                 }
8871                                                                                                                                                                                                                                         }
8872                                                                                                                                                                                                                                 }
8873                                                                                                                                                                                                                         }
8874                                                                                                                                                                                                                 }
8875                                                                                                                                                                                                 }
8876                                                                                                                                                                                                 player[i].CheckKick();
8877                                                                                                                                                                                                 player[k].CheckKick();
8878                                                                                                                                                                         }
8879                                                                                                                                                                 }
8880                                                                 }
8881                                                         }
8882
8883                                                         for(k=0;k<numplayers;k++){
8884                                                                 for(i=k;i<numplayers;i++){
8885                                                                         if(i==k)i++;
8886                                                                         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))){
8887                                                                                 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)){
8888                                                                                         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)){
8889                                                                                                 player[i].victim=&player[k];
8890                                                                                                 player[i].targetanimation=jumpreversedanim;
8891                                                                                                 player[i].currentanimation=jumpreversedanim;
8892                                                                                                 player[k].currentanimation=jumpreversalanim;
8893                                                                                                 player[k].targetanimation=jumpreversalanim;
8894                                                                                                 player[i].targettilt2=0;
8895                                                                                                 player[i].currentframe=0;
8896                                                                                                 player[i].targetframe=1;
8897                                                                                                 player[k].currentframe=0;
8898                                                                                                 player[k].targetframe=1;
8899                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8900                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8901                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8902                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8903                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8904                                                                                                         player[k].currentframe=1;
8905                                                                                                         player[k].targetframe=2;
8906                                                                                                         player[i].currentframe=1;
8907                                                                                                         player[i].targetframe=2;
8908                                                                                                 }
8909                                                                                                 player[k].targettilt2=0;
8910                                                                                                 player[i].target=0;
8911                                                                                                 player[i].velocity=0;
8912                                                                                                 player[k].velocity=0;
8913                                                                                                 player[k].oldcoords=player[k].coords;
8914                                                                                                 player[i].coords=player[k].coords;
8915                                                                                                 player[k].targetrotation=player[i].targetrotation;
8916                                                                                                 player[k].rotation=player[i].targetrotation;
8917                                                                                                 player[k].victim=&player[i];
8918                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8919                                                                                         }
8920                                                                                         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)){
8921                                                                                                 player[k].victim=&player[i];
8922                                                                                                 player[k].targetanimation=jumpreversedanim;
8923                                                                                                 player[k].currentanimation=jumpreversedanim;
8924                                                                                                 player[i].currentanimation=jumpreversalanim;
8925                                                                                                 player[i].targetanimation=jumpreversalanim;
8926                                                                                                 player[k].targettilt2=0;
8927                                                                                                 player[i].targettilt2=0;
8928                                                                                                 player[k].currentframe=0;
8929                                                                                                 player[k].targetframe=1;
8930                                                                                                 player[i].currentframe=0;
8931                                                                                                 player[i].targetframe=1;
8932                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8933                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8934                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8935                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8936                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8937                                                                                                         player[k].currentframe=1;
8938                                                                                                         player[k].targetframe=2;
8939                                                                                                         player[i].currentframe=1;
8940                                                                                                         player[i].targetframe=2;
8941                                                                                                 }
8942                                                                                                 player[k].target=0;
8943                                                                                                 player[k].velocity=0;
8944                                                                                                 player[i].velocity=0;
8945                                                                                                 player[i].oldcoords=player[i].coords;
8946                                                                                                 player[k].coords=player[i].coords;
8947                                                                                                 player[i].targetrotation=player[k].targetrotation;
8948                                                                                                 player[i].rotation=player[k].targetrotation;
8949                                                                                                 player[i].victim=&player[k];
8950                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8951                                                                                         }
8952                                                                                 }
8953                                                                         }
8954                                                                 }
8955                                                         }
8956
8957                                                         for(k=0;k<numplayers;k++)
8958                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8959
8960
8961                                                         //pile
8962                                                         /*
8963                                                         XYZ tempdiff;
8964                                                         XYZ tempoldpos;
8965                                                         XYZ temp1,temp2;
8966                                                         bool isgood;
8967                                                         static float checkdelay;
8968                                                         checkdelay-=multiplier;
8969                                                         int m;
8970                                                         static bool checkedcoll[maxplayers][maxplayers];
8971                                                         static bool above[maxplayers];
8972
8973                                                         for(i=0;i<maxplayers;i++){
8974                                                         for(j=0;j<maxplayers;j++){
8975                                                         checkedcoll[i][j]=0;
8976                                                         }
8977                                                         }
8978
8979                                                         if(numplayers>1&&checkdelay<=0){
8980                                                         checkdelay=.015;
8981                                                         for(k=0;k<numplayers;k++){
8982                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8983
8984                                                         for(i=k;i<numplayers;i++){
8985                                                         if(i==k)i++;
8986                                                         if(i<numplayers)
8987                                                         if(!checkedcoll[i][k]){
8988                                                         checkedcoll[i][k]=1;
8989                                                         checkedcoll[k][i]=1;
8990                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8991                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8992                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8993                                                         if(player[i].coords.y>player[k].coords.y-3)
8994                                                         if(player[i].coords.y<player[k].coords.y+3)
8995                                                         if(player[i].coords.x>player[k].coords.x-3)
8996                                                         if(player[i].coords.x<player[k].coords.x+3)
8997                                                         if(player[i].coords.z>player[k].coords.z-3)
8998                                                         if(player[i].coords.z<player[k].coords.z+3)
8999                                                         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)){
9000                                                         int stuck,moving;
9001                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
9002                                                         stuck=i;
9003                                                         moving=k;
9004                                                         }
9005                                                         else
9006                                                         {
9007                                                         moving=i;
9008                                                         stuck=k;
9009                                                         }
9010                                                         isgood=1;
9011
9012                                                         if(isgood){
9013                                                         above[moving]=stuck;
9014                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
9015                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
9016                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
9017                                                         {
9018                                                         player[moving].skeleton.joints[l].position.y+=.003;
9019                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
9020
9021                                                         }
9022                                                         }
9023                                                         }
9024                                                         }
9025                                                         }
9026                                                         }
9027                                                         }
9028                                                         }
9029                                                         }
9030
9031                                                         */
9032
9033                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
9034                                                                 texturesizetogglekeydown=0;
9035                                                         }
9036
9037                                                         for(k=0;k<numplayers;k++){
9038                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
9039                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
9040                                                                                 player[k].DoDamage(1000);
9041                                                                         }
9042                                                                 }
9043                                                         }
9044
9045                                                         static bool respawnkeydown;
9046                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
9047                                                                 targetlevel=whichlevel;
9048                                                                 loading=1;
9049                                                                 leveltime=5;
9050                                                         }
9051                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
9052                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
9053
9054
9055
9056
9057                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
9058                                                                 targetlevel++;
9059                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
9060                                                                 loading=1;
9061                                                                 leveltime=5;
9062                                                                 slomotogglekeydown=1;
9063                                                         }
9064
9065                                                         /*
9066                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
9067                                                         //Respawn
9068                                                         FSOUND_SetPaused(channels[whooshsound], true);
9069                                                         changedelay=0;
9070                                                         for(k=0;k<numplayers;k++){
9071                                                         player[k].dead=0;
9072                                                         player[k].damage=0;
9073                                                         player[k].permanentdamage=0;
9074                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
9075                                                         player[k].aitype=passivetype;
9076                                                         }
9077                                                         player[0].aitype=playercontrolled;
9078                                                         }
9079                                                         */
9080
9081                                                         static bool movekey;
9082                                                         static bool connected;
9083                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
9084                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
9085                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
9086                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
9087                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
9088                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
9089
9090                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
9091
9092                 for(int i=0;i<numplayers;i++){
9093                                                                 if(!player[i].skeleton.free){
9094                                                                         oldtargetrotation=player[i].targetrotation;
9095                                                                         if(i==0&&indialogue==-1){
9096                                                                                 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){
9097                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
9098                                                                                         if(cameramode)player[0].targetrotation=0;
9099                                                                                 }
9100
9101                                                                                 facing=0;
9102                                                                                 facing.z=-1;
9103
9104                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9105                                                                                 if(cameramode){facing=flatfacing;}
9106                                                                                 else{
9107                                                                                         facing=DoRotation(facing,-rotation2,0,0);
9108                                                                                         facing=DoRotation(facing,0,0-rotation,0);
9109                                                                                 }
9110
9111                                                                                 player[0].lookrotation=-rotation;
9112
9113                                                                                 player[i].targetheadrotation=rotation;
9114                                                                                 player[i].targetheadrotation2=rotation2;
9115                                                                         }
9116                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
9117                                                                                 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){
9118                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
9119                                                                                 }
9120
9121                                                                                 facing=0;
9122                                                                                 facing.z=-1;
9123
9124                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9125
9126                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
9127                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
9128
9129                                                                                 player[i].targetheadrotation=player[i].lookrotation;
9130                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;
9131                                                                         }
9132                                                                         if(indialogue!=-1){
9133                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
9134                                                                                 Normalise(&rotatetarget);
9135                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
9136                                                                                 player[i].targetheadrotation*=360/6.28;
9137                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9138
9139                                                                                 player[i].targetheadrotation*=-1;
9140                                                                                 player[i].targetheadrotation+=180;
9141                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9142                                                                         }
9143
9144                                                                         bool pause;
9145
9146                                                                         if(leveltime<.5)
9147                                                                                 numenvsounds=0;
9148
9149                                                                         player[i].avoidsomething=0;
9150
9151                                                                         for(j=0;j<objects.numobjects;j++){
9152                                                                                 if(objects.onfire[j]){
9153                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
9154                                                                                         {
9155                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
9156                                                                                                         player[i].collided=0;
9157                                                                                                         player[i].avoidcollided=1;
9158                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9159                                                                                                                 player[i].avoidwhere=objects.position[j];
9160                                                                                                 }
9161                                                                                         }
9162                                                                                 }
9163                                                                         }
9164
9165                                                                         //Add avoidwhere to players
9166
9167                                                                         for(j=0;j<numplayers;j++){
9168                                                                                 if(player[j].onfire){
9169                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
9170                                                                                         {
9171                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
9172                                                                                                         player[i].collided=0;
9173                                                                                                         player[i].avoidcollided=1;
9174                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9175                                                                                                                 player[i].avoidwhere=objects.position[j];
9176                                                                                                 }
9177                                                                                         }
9178                                                                                 }
9179                                                                         }
9180
9181                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
9182                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
9183                                                                                 player[i].jumpclimb=0;
9184                                                                                 //AI
9185                                                                                 if(editorenabled)player[i].stunned=1;
9186
9187                                                                                 player[i].pause=0;
9188                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
9189                                                                                 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;
9190
9191                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
9192                                                                                 player[i].forwardkeydown=0;
9193                                                                                 player[i].leftkeydown=0;
9194                                                                                 player[i].backkeydown=0;
9195                                                                                 player[i].rightkeydown=0;
9196                                                                                 player[i].crouchkeydown=0;
9197                                                                                 player[i].attackkeydown=0;
9198                                                                                 player[i].jumpkeydown=0;
9199                                                                                 player[i].throwkeydown=0;
9200                                                                                 }*/
9201
9202                                                                                 if(player[i].aitype==pathfindtype){
9203                                                                                         if(player[i].finalpathfindpoint==-1){
9204                                                                                                 float closestdistance;
9205                                                                                                 float tempdist;
9206                                                                                                 int closest;
9207                                                                                                 XYZ colpoint;
9208                                                                                                 closest=-1;
9209                                                                                                 closestdistance=-1;
9210                                                                                                 for(j=0;j<numpathpoints;j++){
9211                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
9212                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
9213                                                                                                                 closest=j;
9214                                                                                                                 player[i].finaltarget=pathpoint[j];
9215                                                                                                         }
9216                                                                                                 }
9217                                                                                                 player[i].finalpathfindpoint=closest;
9218                                                                                                 for(j=0;j<numpathpoints;j++){
9219                                                                                                         if(numpathpointconnect[j])
9220                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9221                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9222                                                                                                                         if(tempdist*tempdist<closestdistance){
9223                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9224                                                                                                                                         closestdistance=tempdist*tempdist;
9225                                                                                                                                         closest=j;
9226                                                                                                                                         player[i].finaltarget=colpoint;
9227                                                                                                                                 }
9228                                                                                                                         }
9229                                                                                                                 }
9230                                                                                                 }
9231                                                                                                 player[i].finalpathfindpoint=closest;
9232
9233                                                                                         }
9234                                                                                         if(player[i].targetpathfindpoint==-1){
9235                                                                                                 float closestdistance;
9236                                                                                                 float tempdist;
9237                                                                                                 int closest;
9238                                                                                                 XYZ colpoint;
9239                                                                                                 closest=-1;
9240                                                                                                 closestdistance=-1;
9241                                                                                                 if(player[i].lastpathfindpoint==-1){
9242                                                                                                         for(j=0;j<numpathpoints;j++){
9243                                                                                                                 if(j!=player[i].lastpathfindpoint)
9244                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
9245                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
9246                                                                                                                                 closest=j;
9247                                                                                                                         }
9248                                                                                                         }
9249                                                                                                         player[i].targetpathfindpoint=closest;
9250                                                                                                         for(j=0;j<numpathpoints;j++){
9251                                                                                                                 if(j!=player[i].lastpathfindpoint)
9252                                                                                                                         if(numpathpointconnect[j])
9253                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9254                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9255                                                                                                                                         if(tempdist*tempdist<closestdistance){
9256                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9257                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
9258                                                                                                                                                         closestdistance=tempdist*tempdist;
9259                                                                                                                                                         closest=j;
9260                                                                                                                                                         //}
9261                                                                                                                                                 }
9262                                                                                                                                         }
9263                                                                                                                                 }
9264                                                                                                         }
9265                                                                                                         player[i].targetpathfindpoint=closest;
9266                                                                                                 }
9267                                                                                                 else
9268                                                                                                 {
9269                                                                                                         for(j=0;j<numpathpoints;j++){
9270                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
9271                                                                                                                 {
9272                                                                                                                         connected=0;
9273                                                                                                                         if(numpathpointconnect[j])
9274                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9275                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
9276                                                                                                                                 }
9277                                                                                                                                 if(!connected)
9278                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
9279                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
9280                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
9281                                                                                                                                                 }
9282                                                                                                                                                 if(connected){
9283                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
9284                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
9285                                                                                                                                                                 closestdistance=tempdist;
9286                                                                                                                                                                 closest=j;
9287                                                                                                                                                         }
9288                                                                                                                                                 }
9289                                                                                                                 }
9290                                                                                                         }
9291                                                                                                         player[i].targetpathfindpoint=closest;
9292                                                                                                 }
9293                                                                                         }
9294                                                                                         player[i].losupdatedelay-=multiplier;
9295
9296                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
9297                                                                                         Normalise(&rotatetarget);
9298                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9299                                                                                         player[i].targetrotation*=360/6.28;
9300                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9301                                                                                         player[i].lookrotation=player[i].targetrotation;
9302                                                                                         //player[i].aiupdatedelay=.05;
9303
9304                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
9305                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9306                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9307                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9308                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
9309                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9310                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9311                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9312                                                                                                 player[i].targetpathfindpoint=-1;
9313                                                                                         }
9314                                                                                         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){
9315                                                                                                 player[i].aitype=passivetype;
9316                                                                                         }
9317
9318                                                                                         player[i].forwardkeydown=1;
9319                                                                                         player[i].leftkeydown=0;
9320                                                                                         player[i].backkeydown=0;
9321                                                                                         player[i].rightkeydown=0;
9322                                                                                         player[i].crouchkeydown=0;
9323                                                                                         player[i].attackkeydown=0;
9324                                                                                         player[i].throwkeydown=0;
9325
9326                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
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                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9332                                                                                                 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))
9333                                                                                                         player[i].aitype=attacktypecutoff;
9334                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9335                                                                                                         player[i].aitype=attacktypecutoff;
9336
9337                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9338                                                                                                         player[i].losupdatedelay=.2;
9339                                                                                                         for(j=0;j<numplayers;j++){
9340                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9341                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9342                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9343                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9344                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9345                                                                                                                                                         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)){
9346                                                                                                                                                                 player[i].aitype=searchtype;
9347                                                                                                                                                                 player[i].lastchecktime=12;
9348                                                                                                                                                                 player[i].lastseen=player[j].coords;
9349                                                                                                                                                                 player[i].lastseentime=12;
9350                                                                                                                                                         }
9351                                                                                                                 }
9352                                                                                                         }
9353                                                                                                 }
9354                                                                                         }
9355                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9356                                                                                                 if(player[i].creature!=wolftype){
9357                                                                                                         player[i].stunned=.6;
9358                                                                                                         player[i].surprised=.6;
9359                                                                                                 }
9360                                                                                         }
9361                                                                                 }
9362
9363                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9364                                                                                         player[i].howactive=typeactive;
9365                                                                                 }
9366
9367                                                                                 if(player[i].aitype==passivetype){
9368                                                                                         player[i].aiupdatedelay-=multiplier;
9369                                                                                         player[i].losupdatedelay-=multiplier;
9370                                                                                         player[i].lastseentime+=multiplier;
9371                                                                                         player[i].pausetime-=multiplier;
9372                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9373
9374                                                                                         if(player[i].aiupdatedelay<0){
9375                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9376                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9377                                                                                                         Normalise(&rotatetarget);
9378                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9379                                                                                                         player[i].targetrotation*=360/6.28;
9380                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9381                                                                                                         player[i].lookrotation=player[i].targetrotation;
9382                                                                                                         player[i].aiupdatedelay=.05;
9383
9384                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9385                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9386                                                                                                                 player[i].waypoint++;
9387                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9388
9389                                                                                                         }
9390                                                                                                 }
9391
9392                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9393                                                                                                 else player[i].forwardkeydown=0;
9394                                                                                                 player[i].leftkeydown=0;
9395                                                                                                 player[i].backkeydown=0;
9396                                                                                                 player[i].rightkeydown=0;
9397                                                                                                 player[i].crouchkeydown=0;
9398                                                                                                 player[i].attackkeydown=0;
9399                                                                                                 player[i].throwkeydown=0;
9400
9401                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9402                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9403                                                                                                         else{
9404                                                                                                                 XYZ leftpos,rightpos;
9405                                                                                                                 float leftdist,rightdist;
9406                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9407                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9408                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9409                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9410                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9411                                                                                                                 else player[i].targetrotation-=90;
9412                                                                                                         }
9413                                                                                                 }
9414                                                                                         }
9415                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9416                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9417
9418
9419                                                                                         if(!editorenabled){
9420                                                                                                 if(player[i].howactive<typesleeping)
9421                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9422                                                                                                                 for(j=0;j<numenvsounds;j++){
9423                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9424                                                                                                                                 player[i].aitype=attacktypecutoff;
9425                                                                                                                         }
9426                                                                                                                 }
9427
9428                                                                                                                 if(player[i].howactive==typesleeping)
9429                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9430                                                                                                                                 for(j=0;j<numenvsounds;j++){
9431                                                                                                                                         if(envsoundvol[j]>14)
9432                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9433                                                                                                                                                         player[i].aitype=attacktypecutoff;
9434                                                                                                                                                 }
9435                                                                                                                                 }
9436
9437                                                                                                                                 if(player[i].aitype!=passivetype){
9438                                                                                                                                         if(player[i].howactive==typesleeping){
9439                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9440                                                                                                                                                 player[i].targetframe=0;
9441                                                                                                                                                 player[i].target=0;
9442                                                                                                                                         }
9443
9444                                                                                                                                         player[i].howactive=typeactive;
9445                                                                                                                                 }
9446                                                                                         }
9447
9448                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9449                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9450                                                                                                         player[i].aitype=attacktypecutoff;
9451                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9452                                                                                                         player[i].aitype=attacktypecutoff;
9453
9454                                                                                                 if(player[i].creature==wolftype){
9455                                                                                                         XYZ windsmell;
9456                                                                                                         float smelldistance;
9457                                                                                                         smelldistance=50;
9458                                                                                                         for(j=0;j<numplayers;j++){
9459                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9460                                                                                                                         if(j==0&&player[j].num_weapons>0){
9461                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9462                                                                                                                                 if(player[j].num_weapons==2)
9463                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9464                                                                                                                         }
9465                                                                                                                         if(j!=0){
9466                                                                                                                                 smelldistance=100;
9467                                                                                                                         }
9468                                                                                                                         windsmell=windvector;
9469                                                                                                                         Normalise(&windsmell);
9470                                                                                                                         windsmell=windsmell*2+player[j].coords;
9471                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9472                                                                                                                                 player[i].aitype=attacktypecutoff;
9473                                                                                                                 }
9474                                                                                                         }
9475                                                                                                 }
9476
9477                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9478                                                                                                         player[i].losupdatedelay=.2;
9479                                                                                                         for(j=0;j<numplayers;j++){
9480                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9481                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9482                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9483                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9484                                                                                                                                                 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)){
9485                                                                                                                                                         player[i].lastseentime-=.2;
9486                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9487                                                                                                                                                         else player[i].lastseentime-=.6;
9488                                                                                                                                                 }
9489                                                                                                                                                 if(player[i].lastseentime<=0){
9490                                                                                                                                                         player[i].aitype=searchtype;
9491                                                                                                                                                         player[i].lastchecktime=12;
9492                                                                                                                                                         player[i].lastseen=player[j].coords;
9493                                                                                                                                                         player[i].lastseentime=12;
9494                                                                                                                                                 }
9495                                                                                                                 }
9496                                                                                                         }
9497                                                                                                 }
9498                                                                                         }
9499                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9500                                                                                                 if(player[i].creature!=wolftype){
9501                                                                                                         player[i].stunned=.6;
9502                                                                                                         player[i].surprised=.6;
9503                                                                                                 }
9504                                                                                                 if(player[i].creature==wolftype){
9505                                                                                                         player[i].stunned=.47;
9506                                                                                                         player[i].surprised=.47;
9507                                                                                                 }
9508                                                                                                 numseen++;
9509                                                                                         }
9510                                                                                 }
9511
9512                                                                                 if(player[i].aitype==searchtype){
9513                                                                                         player[i].aiupdatedelay-=multiplier;
9514                                                                                         player[i].losupdatedelay-=multiplier;
9515                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9516                                                                                         player[i].lastchecktime-=multiplier;
9517
9518                                                                                         if(player[i].isRun()&&!player[i].onground){
9519                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9520                                                                                                         test2=player[i].coords+player[i].facing;
9521                                                                                                         test2.y+=5;
9522                                                                                                         test=player[i].coords+player[i].facing;
9523                                                                                                         test.y-=10;
9524                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9525                                                                                                         if(j==-1)j=checkcollide(test2,test);
9526                                                                                                         if(j==-1){
9527                                                                                                                 player[i].velocity=0;
9528                                                                                                                 player[i].targetanimation=player[i].getStop();
9529                                                                                                                 player[i].targetframe=0;
9530                                                                                                                 player[i].target=0;
9531                                                                                                                 player[i].targetrotation+=180;
9532                                                                                                                 player[i].stunned=.5;
9533                                                                                                                 //player[i].aitype=passivetype;
9534                                                                                                                 player[i].aitype=pathfindtype;
9535                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9536                                                                                                                 player[i].finalpathfindpoint=-1;
9537                                                                                                                 player[i].targetpathfindpoint=-1;
9538                                                                                                                 player[i].lastpathfindpoint=-1;
9539                                                                                                                 player[i].lastpathfindpoint2=-1;
9540                                                                                                                 player[i].lastpathfindpoint3=-1;
9541                                                                                                                 player[i].lastpathfindpoint4=-1;
9542                                                                                                         }
9543                                                                                                         else player[i].laststanding=j;
9544                                                                                                 }
9545                                                                                         }
9546                                                                                         if(player[i].aiupdatedelay<0){
9547                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9548                                                                                                 Normalise(&rotatetarget);
9549                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9550                                                                                                 player[i].targetrotation*=360/6.28;
9551                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9552                                                                                                 player[i].lookrotation=player[i].targetrotation;
9553                                                                                                 player[i].aiupdatedelay=.05;
9554                                                                                                 player[i].forwardkeydown=1;
9555
9556                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9557                                                                                                         player[i].forwardkeydown=0;
9558                                                                                                         player[i].aiupdatedelay=1;
9559                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9560                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9561                                                                                                         player[i].lastchecktime=3;
9562                                                                                                 }
9563
9564                                                                                                 player[i].leftkeydown=0;
9565                                                                                                 player[i].backkeydown=0;
9566                                                                                                 player[i].rightkeydown=0;
9567                                                                                                 player[i].crouchkeydown=0;
9568                                                                                                 player[i].attackkeydown=0;
9569                                                                                                 player[i].throwkeydown=0;
9570
9571                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9572                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9573                                                                                                         else{
9574                                                                                                                 XYZ leftpos,rightpos;
9575                                                                                                                 float leftdist,rightdist;
9576                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9577                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9578                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9579                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9580                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9581                                                                                                                 else player[i].targetrotation-=90;
9582                                                                                                         }
9583                                                                                                 }
9584                                                                                         }
9585                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9586                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9587
9588                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9589                                                                                                 for(j=0;j<numenvsounds;j++){
9590                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9591                                                                                                                 player[i].aitype=attacktypecutoff;
9592                                                                                                         }
9593                                                                                                 }
9594
9595                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9596                                                                                                         player[i].losupdatedelay=.2;
9597                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9598                                                                                                         {player[i].aitype=attacktypecutoff;
9599                                                                                                         player[i].lastseentime=1;}
9600                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9601                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9602                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9603                                                                                                                                 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)){
9604                                                                                                                                         player[i].aitype=attacktypecutoff;
9605                                                                                                                                         player[i].lastseentime=1;
9606                                                                                                                                 }
9607                                                                                                 }
9608                                                                                                 if(player[i].lastseentime<0){
9609                                                                                                         //player[i].aitype=passivetype;
9610                                                                                                         numescaped++;
9611                                                                                                         player[i].aitype=pathfindtype;
9612                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9613                                                                                                         player[i].finalpathfindpoint=-1;
9614                                                                                                         player[i].targetpathfindpoint=-1;
9615                                                                                                         player[i].lastpathfindpoint=-1;
9616                                                                                                         player[i].lastpathfindpoint2=-1;
9617                                                                                                         player[i].lastpathfindpoint3=-1;
9618                                                                                                         player[i].lastpathfindpoint4=-1;
9619                                                                                                 }
9620                                                                                 }
9621
9622                                                                                 if(player[i].aitype!=gethelptype){
9623                                                                                         player[i].runninghowlong=0;
9624                                                                                 }
9625
9626                                                                                 if(player[i].aitype==gethelptype){
9627                                                                                         player[i].runninghowlong+=multiplier;
9628                                                                                         player[i].aiupdatedelay-=multiplier;
9629
9630                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9631                                                                                                 player[i].aiupdatedelay=.2;
9632
9633                                                                                                 int closest;
9634                                                                                                 float closestdist;
9635                                                                                                 closest=-1;
9636                                                                                                 closestdist=-1;
9637                                                                                                 float distance;
9638
9639                                                                                                 if(!player[i].ally){
9640                                                                                                         for(j=0;j<numplayers;j++){
9641                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9642                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9643                                                                                                                         if(closestdist==-1||distance<closestdist){
9644                                                                                                                                 closestdist=distance;
9645                                                                                                                                 closest=j;
9646                                                                                                                         }
9647                                                                                                                         closest=j;
9648                                                                                                                 }
9649                                                                                                         }
9650                                                                                                         if(closest!=-1)player[i].ally=closest;
9651                                                                                                         else player[i].ally=0;
9652                                                                                                         player[i].lastseen=player[0].coords;
9653                                                                                                         player[i].lastseentime=12;
9654                                                                                                 }
9655
9656
9657                                                                                                 player[i].lastchecktime=12;
9658                                                                                                 //player[i].lastseentime-=.5;
9659
9660                                                                                                 facing=player[i].coords;
9661                                                                                                 flatfacing=player[player[i].ally].coords;
9662                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9663                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9664                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9665                                                                                                         player[i].lastseentime-=.1;
9666
9667                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9668                                                                                                         player[i].aitype=searchtype;
9669                                                                                                         player[i].lastseentime=12;
9670                                                                                                 }
9671
9672                                                                                                 if(player[i].ally>0){
9673                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9674                                                                                                         Normalise(&rotatetarget);
9675                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9676                                                                                                         player[i].targetrotation*=360/6.28;
9677                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9678                                                                                                         player[i].lookrotation=player[i].targetrotation;
9679                                                                                                         player[i].aiupdatedelay=.05;
9680                                                                                                         player[i].forwardkeydown=1;
9681
9682                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9683                                                                                                                 player[i].aitype=searchtype;
9684                                                                                                                 player[i].lastseentime=12;
9685                                                                                                                 player[player[i].ally].aitype=searchtype;
9686                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9687                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9688                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9689                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9690                                                                                                                 }
9691                                                                                                         }
9692
9693                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9694                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9695                                                                                                                 else{
9696                                                                                                                         XYZ leftpos,rightpos;
9697                                                                                                                         float leftdist,rightdist;
9698                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9699                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9700                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9701                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9702                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9703                                                                                                                         else player[i].targetrotation-=90;
9704                                                                                                                 }
9705                                                                                                         }
9706                                                                                                 }
9707
9708                                                                                                 player[i].leftkeydown=0;
9709                                                                                                 player[i].backkeydown=0;
9710                                                                                                 player[i].rightkeydown=0;
9711                                                                                                 player[i].crouchkeydown=0;
9712                                                                                                 player[i].attackkeydown=0;
9713                                                                                         }
9714                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9715                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9716                                                                                 }
9717
9718                                                                                 if(player[i].aitype==getweapontype){
9719                                                                                         player[i].aiupdatedelay-=multiplier;
9720                                                                                         player[i].lastchecktime-=multiplier;
9721
9722                                                                                         if(player[i].aiupdatedelay<0){
9723                                                                                                 player[i].aiupdatedelay=.2;
9724
9725                                                                                                 int closest;
9726                                                                                                 float closestdist;
9727                                                                                                 closest=-1;
9728                                                                                                 closestdist=-1;
9729                                                                                                 float distance;
9730
9731                                                                                                 if(player[i].ally<0){
9732                                                                                                         for(j=0;j<weapons.numweapons;j++){
9733                                                                                                                 if(weapons.owner[j]==-1){
9734                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9735                                                                                                                         if(closestdist==-1||distance<closestdist){
9736                                                                                                                                 closestdist=distance;
9737                                                                                                                                 closest=j;
9738                                                                                                                         }
9739                                                                                                                         closest=j;
9740                                                                                                                 }
9741                                                                                                         }
9742                                                                                                         if(closest!=-1)player[i].ally=closest;
9743                                                                                                         else player[i].ally=-1;
9744                                                                                                 }
9745
9746                                                                                                 player[i].lastseentime=12;
9747
9748                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9749                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9750                                                                                                                 player[i].aitype=attacktypecutoff;
9751                                                                                                                 player[i].lastseentime=1;
9752                                                                                                         }
9753                                                                                                         if(!player[0].dead)
9754                                                                                                                 if(player[i].ally>=0){
9755                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9756                                                                                                                                 player[i].aitype=attacktypecutoff;
9757                                                                                                                                 player[i].lastseentime=1;
9758                                                                                                                         }
9759                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9760                                                                                                                         Normalise(&rotatetarget);
9761                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9762                                                                                                                         player[i].targetrotation*=360/6.28;
9763                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9764                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9765                                                                                                                         player[i].aiupdatedelay=.05;
9766                                                                                                                         player[i].forwardkeydown=1;
9767
9768
9769                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9770                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9771                                                                                                                                 else{
9772                                                                                                                                         XYZ leftpos,rightpos;
9773                                                                                                                                         float leftdist,rightdist;
9774                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9775                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9776                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9777                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9778                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9779                                                                                                                                         else player[i].targetrotation-=90;
9780                                                                                                                                 }
9781                                                                                                                         }
9782                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9783                                                                                                                         if(abs(Random()%6)){
9784                                                                                                                         player[i].crouchkeydown=1;
9785                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9786                                                                                                                         if(player[i].isRun()){
9787                                                                                                                         player[i].targetframe=0;
9788                                                                                                                         player[i].target=0;
9789                                                                                                                         player[i].targetanimation=sneakanim;
9790                                                                                                                         }
9791                                                                                                                         }
9792                                                                                                                         else player[i].forwardkeydown=0;
9793                                                                                                                         }
9794                                                                                                                         else player[i].crouchkeydown=0;
9795                                                                                                                         }
9796                                                                                                                         else player[i].crouchkeydown=0;*/
9797                                                                                                                 }
9798
9799                                                                                                                 player[i].leftkeydown=0;
9800                                                                                                                 player[i].backkeydown=0;
9801                                                                                                                 player[i].rightkeydown=0;
9802                                                                                                                 player[i].attackkeydown=0;
9803                                                                                                                 player[i].throwkeydown=1;
9804                                                                                                                 player[i].crouchkeydown=0;
9805                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9806                                                                                                                 player[i].drawkeydown=0;
9807                                                                                         }
9808                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9809                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9810                                                                                 }
9811
9812                                                                                 if(player[i].aitype==attacktypecutoff){
9813                                                                                         player[i].aiupdatedelay-=multiplier;
9814                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9815                                                                                                 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)){
9816                                                                                                         player[i].attackkeydown=0;
9817                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9818                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9819                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9820                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9821                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9822                                                                                                                                 else player[i].targetanimation=rollanim;
9823                                                                                                                                 player[i].target=0;
9824                                                                                                                                 player[i].targetframe=0;
9825                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9826                                                                                                                                 player[i].wentforweapon=0;
9827                                                                                                                         }
9828                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9829                                                                                                                                 player[i].targetanimation=flipanim;
9830                                                                                                                                 player[i].target=0;
9831                                                                                                                                 player[i].targetframe=0;
9832                                                                                                                         }
9833                                                                                                                 }
9834                                                                                                         }
9835                                                                                                         player[i].forwardkeydown=0;
9836                                                                                                         player[i].aiupdatedelay=.02;
9837                                                                                                 }
9838                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9839                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9840                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9841                                                                                                 }
9842                                                                                                 if(player[i].wentforweapon<3)
9843                                                                                                         for(j=0;j<weapons.numweapons;j++){
9844                                                                                                                 if(player[i].creature!=wolftype)
9845                                                                                                                         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){
9846                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9847                                                                                                                                         player[i].wentforweapon++;
9848                                                                                                                                         player[i].lastchecktime=6;
9849                                                                                                                                         player[i].aitype=getweapontype;
9850                                                                                                                                         player[i].ally=-1;
9851                                                                                                                                 }
9852                                                                                                                         }
9853                                                                                                         }
9854                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9855                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9856                                                                                                                         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)))){
9857                                                                                                                                 player[i].crouchkeydown=1;
9858                                                                                                                         }
9859                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9860                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9861                                                                                                                                         test2=player[i].coords+player[i].facing;
9862                                                                                                                                         test2.y+=5;
9863                                                                                                                                         test=player[i].coords+player[i].facing;
9864                                                                                                                                         test.y-=10;
9865                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9866                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9867                                                                                                                                         if(j==-1){
9868                                                                                                                                                 player[i].velocity=0;
9869                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9870                                                                                                                                                 player[i].targetframe=0;
9871                                                                                                                                                 player[i].target=0;
9872                                                                                                                                                 player[i].targetrotation+=180;
9873                                                                                                                                                 player[i].stunned=.5;
9874                                                                                                                                                 //player[i].aitype=passivetype;
9875                                                                                                                                                 player[i].aitype=pathfindtype;
9876                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9877                                                                                                                                                 player[i].finalpathfindpoint=-1;
9878                                                                                                                                                 player[i].targetpathfindpoint=-1;
9879                                                                                                                                                 player[i].lastpathfindpoint=-1;
9880                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9881                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9882                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9883                                                                                                                                         }
9884                                                                                                                                         else player[i].laststanding=j;
9885                                                                                                                                 }
9886                                                                                                                         }
9887                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9888                                                                                                                                 player[i].aitype=pathfindtype;
9889                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9890                                                                                                                                 player[i].finalpathfindpoint=-1;
9891                                                                                                                                 player[i].targetpathfindpoint=-1;
9892                                                                                                                                 player[i].lastpathfindpoint=-1;
9893                                                                                                                                 player[i].lastpathfindpoint2=-1;
9894                                                                                                                                 player[i].lastpathfindpoint3=-1;
9895                                                                                                                                 player[i].lastpathfindpoint4=-1;
9896                                                                                                                         }
9897                                                                                                                         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){
9898                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9899                                                                                                                                 else player[i].drawkeydown=0;
9900                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9901                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9902                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9903                                                                                                                                         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;
9904                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9905                                                                                                                                 Normalise(&rotatetarget);
9906                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9907                                                                                                                                 player[i].targetrotation*=360/6.28;
9908                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9909                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9910                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9911
9912                                                                                                                                 oldkey=player[i].forwardkeydown;
9913                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9914                                                                                                                                 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;
9915                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9916                                                                                                                                 else player[i].forwardkeydown=0;
9917                                                                                                                                 if(player[0].dead){
9918                                                                                                                                         player[i].forwardkeydown=0;
9919                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9920                                                                                                                                         if(Random()%100==0){
9921                                                                                                                                                 player[i].aitype=pathfindtype;
9922                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9923                                                                                                                                                 player[i].finalpathfindpoint=-1;
9924                                                                                                                                                 player[i].targetpathfindpoint=-1;
9925                                                                                                                                                 player[i].lastpathfindpoint=-1;
9926                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9927                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9928                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9929                                                                                                                                         }
9930                                                                                                                                 }
9931                                                                                                                                 player[i].leftkeydown=0;
9932                                                                                                                                 player[i].backkeydown=0;
9933                                                                                                                                 player[i].rightkeydown=0;
9934                                                                                                                                 player[i].crouchkeydown=0;
9935                                                                                                                                 player[i].throwkeydown=0;
9936
9937                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9938                                                                                                                                 /*for(j=0;j<numplayers;j++){
9939                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9940                                                                                                                                 player[i].crouchkeydown=1;
9941                                                                                                                                 }
9942                                                                                                                                 }*/
9943                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9944                                                                                                                                 else player[i].attackkeydown=0;
9945                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9946                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9947                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9948                                                                                                                                 player[i].attackkeydown=0;
9949                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9950                                                                                                                                 player[i].forwardkeydown=0;
9951                                                                                                                                 player[i].aiupdatedelay=.02;
9952                                                                                                                                 }*/
9953
9954                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9955                                                                                                                                         target=-2;
9956                                                                                                                                         for(j=0;j<numplayers;j++){
9957                                                                                                                                                 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)){
9958                                                                                                                                                         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))))){
9959                                                                                                                                                                 if(target>=0)target=-1;
9960                                                                                                                                                                 else target=j;
9961                                                                                                                                                         }
9962                                                                                                                                                 }
9963                                                                                                                                         }
9964                                                                                                                                         if(target>=0)player[target].Reverse();
9965                                                                                                                                 }
9966
9967                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9968                                                                                                                                 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;
9969                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9970                                                                                                                                         player[0].jumpkeydown=0;
9971                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9972                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9973                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9974
9975                                                                                                                                 if(tutoriallevel==1){
9976                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9977                                                                                                                                 }
9978
9979
9980                                                                                                                                 facing=player[i].coords;
9981                                                                                                                                 flatfacing=player[0].coords;
9982                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9983                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9984                                                                                                                                 if(player[i].occluded>=2)
9985                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9986                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9987                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9988                                                                                                                                                         player[i].aitype=searchtype;
9989                                                                                                                                                         player[i].lastchecktime=12;
9990                                                                                                                                                         player[i].lastseen=player[0].coords;
9991                                                                                                                                                         player[i].lastseentime=12;
9992                                                                                                                                                 }
9993                                                                                                                                         }
9994                                                                                                                                         else player[i].lastseentime=1;
9995                                                                                                                         }
9996                                                                                 }
9997                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9998                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9999                                                                                                 test=player[0].coords;
10000                                                                                                 test.y-=40;
10001                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
10002                                                                                         }
10003                                                                                 }
10004                                                                                 // NOTE: Ask about logic of this call : NOTE
10005                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
10006                                                                                         player[i].stunned>0 ||
10007                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
10008                                                                                 {
10009                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
10010                                                                                         player[i].targetrotation=player[i].rotation;
10011                                                                                         player[i].forwardkeydown=0;
10012                                                                                         player[i].leftkeydown=0;
10013                                                                                         player[i].backkeydown=0;
10014                                                                                         player[i].rightkeydown=0;
10015                                                                                         player[i].jumpkeydown=0;
10016                                                                                         player[i].attackkeydown=0;
10017                                                                                         player[i].crouchkeydown=0;
10018                                                                                         player[i].throwkeydown=0;
10019                                                                                 }
10020
10021
10022                                                                                 facing=0;
10023                                                                                 facing.z=-1;
10024
10025                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
10026                                                                                 facing=flatfacing;
10027
10028                                                                                 if(player[i].aitype==attacktypecutoff){
10029                                                                                         rotatetarget=player[0].coords-player[i].coords;
10030                                                                                         Normalise(&rotatetarget);
10031                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
10032                                                                                         player[i].targetheadrotation*=360/6.28;
10033                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
10034
10035                                                                                         player[i].targetheadrotation*=-1;
10036                                                                                         player[i].targetheadrotation+=180;
10037                                                                                         //player[i].targetheadrotation2=0;
10038                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
10039                                                                                 }
10040                                                                                 else if(player[i].howactive>=typesleeping){
10041                                                                                         player[i].targetheadrotation=player[i].targetrotation;
10042                                                                                         player[i].targetheadrotation2=0;
10043                                                                                 }
10044                                                                                 else {
10045                                                                                         if(player[i].interestdelay<=0){
10046                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
10047                                                                                                 player[i].headtarget=player[i].coords;
10048                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
10049                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
10050                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
10051                                                                                                 player[i].headtarget+=player[i].facing*1.5;
10052                                                                                         }
10053                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
10054                                                                                         Normalise(&rotatetarget);
10055                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
10056                                                                                         player[i].targetheadrotation*=360/6.28;
10057                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
10058
10059                                                                                         player[i].targetheadrotation*=-1;
10060                                                                                         player[i].targetheadrotation+=180;
10061                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
10062                                                                                 }
10063                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
10064                                                                         }
10065                                                                         if(animation[player[i].targetanimation].attack==reversed){
10066                                                                                 //player[i].targetrotation=player[i].rotation;
10067                                                                                 player[i].forwardkeydown=0;
10068                                                                                 player[i].leftkeydown=0;
10069                                                                                 player[i].backkeydown=0;
10070                                                                                 player[i].rightkeydown=0;
10071                                                                                 player[i].jumpkeydown=0;
10072                                                                                 player[i].attackkeydown=0;
10073                                                                                 //player[i].crouchkeydown=0;
10074                                                                                 player[i].throwkeydown=0;
10075                                                                         }
10076
10077                                                                         if(indialogue!=-1){
10078                                                                                 player[i].forwardkeydown=0;
10079                                                                                 player[i].leftkeydown=0;
10080                                                                                 player[i].backkeydown=0;
10081                                                                                 player[i].rightkeydown=0;
10082                                                                                 player[i].jumpkeydown=0;
10083                                                                                 player[i].crouchkeydown=0;
10084                                                                                 player[i].drawkeydown=0;
10085                                                                                 player[i].throwkeydown=0;
10086                                                                         }
10087
10088                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
10089                                                                         if(player[i].collided>1)player[i].collided=1;
10090                                                                         player[i].collided-=multiplier*4;
10091                                                                         player[i].whichdirectiondelay-=multiplier;
10092                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
10093                                                                                 player[i].avoidcollided=-.3;
10094                                                                                 player[i].whichdirection=abs(Random()%2);
10095                                                                                 player[i].whichdirectiondelay=.4;
10096                                                                         }
10097                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
10098                                                                         player[i].avoidcollided-=multiplier/4;
10099                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
10100                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
10101                                                                         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;
10102
10103                                                                         if(!player[i].throwkeydown){
10104                                                                                 player[i].throwtogglekeydown=0;
10105                                                                         }
10106                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
10107                                                                                 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)){
10108                                                                                         for(j=0;j<weapons.numweapons;j++){
10109                                                                                                 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)
10110                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
10111                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
10112                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
10113                                                                                                                                 player[i].throwtogglekeydown=1;
10114                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10115                                                                                                                                 player[i].target=0;
10116                                                                                                                                 player[i].targetframe=0;
10117                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10118                                                                                                                                 Normalise(&rotatetarget);
10119                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10120                                                                                                                                 player[i].targetrotation*=360/6.28;
10121                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10122                                                                                                                                 player[i].hasvictim=0;
10123                                                                                                                         }
10124                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10125                                                                                                                                 player[i].throwtogglekeydown=1;
10126                                                                                                                                 player[i].hasvictim=0;
10127
10128                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
10129                                                                                                                                 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))
10130                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
10131                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
10132                                                                                                                                                         float gLoc[3];
10133                                                                                                                                                         float vel[3];
10134                                                                                                                                                         gLoc[0]=player[i].coords.x;
10135                                                                                                                                                         gLoc[1]=player[i].coords.y;
10136                                                                                                                                                         gLoc[2]=player[i].coords.z;
10137                                                                                                                                                         vel[0]=player[i].velocity.x;
10138                                                                                                                                                         vel[1]=player[i].velocity.y;
10139                                                                                                                                                         vel[2]=player[i].velocity.z;
10140                                                                                                                                                         if(weapons.type[j]!=staff){
10141                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10142                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10143                                                                                                                                                                 FSOUND_SetVolume(channels[knifedrawsound], 128);
10144                                                                                                                                                                 FSOUND_SetPaused(channels[knifedrawsound], false);
10145                                                                                                                                                         }
10146
10147                                                                                                                                                         player[i].weaponactive=0;
10148                                                                                                                                                         weapons.owner[j]=player[i].id;
10149                                                                                                                                                         if(player[i].num_weapons>0){
10150                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10151                                                                                                                                                         }
10152                                                                                                                                                         player[i].num_weapons++;
10153                                                                                                                                                         player[i].weaponids[0]=j;
10154                                                                                                                                                 }
10155                                                                                                                                         }
10156                                                                                                                                         //}
10157                                                                                                                         }
10158                                                                                                                 }
10159                                                                                                                 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){
10160                                                                                                                         if(!player[i].isFlip()){
10161                                                                                                                                 player[i].throwtogglekeydown=1;
10162                                                                                                                                 player[i].targetanimation=removeknifeanim;
10163                                                                                                                                 player[i].target=0;
10164                                                                                                                                 player[i].targetframe=0;
10165                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10166                                                                                                                                 Normalise(&rotatetarget);
10167                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10168                                                                                                                                 player[i].targetrotation*=360/6.28;
10169                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10170                                                                                                                         }
10171                                                                                                                         if(player[i].isFlip()){
10172                                                                                                                                 player[i].throwtogglekeydown=1;
10173                                                                                                                                 player[i].hasvictim=0;
10174
10175                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
10176                                                                                                                                         if(player[i].weaponactive==-1)
10177                                                                                                                                                 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))
10178                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
10179                                                                                                                                                                 float gLoc[3];
10180                                                                                                                                                                 float vel[3];
10181                                                                                                                                                                 gLoc[0]=player[i].coords.x;
10182                                                                                                                                                                 gLoc[1]=player[i].coords.y;
10183                                                                                                                                                                 gLoc[2]=player[i].coords.z;
10184                                                                                                                                                                 vel[0]=player[i].velocity.x;
10185                                                                                                                                                                 vel[1]=player[i].velocity.y;
10186                                                                                                                                                                 vel[2]=player[i].velocity.z;
10187                                                                                                                                                                 if(weapons.type[k]!=staff){
10188                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10189                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10190                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10191                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], false);
10192                                                                                                                                                                 }
10193
10194                                                                                                                                                                 player[i].weaponactive=0;
10195                                                                                                                                                                 weapons.owner[k]=player[i].id;
10196                                                                                                                                                                 if(player[i].num_weapons>0){
10197                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10198                                                                                                                                                                 }
10199                                                                                                                                                                 player[i].num_weapons++;
10200                                                                                                                                                                 player[i].weaponids[0]=k;
10201                                                                                                                                                         }
10202                                                                                                                                 }
10203                                                                                                                         }
10204                                                                                                                 }
10205                                                                                                         }
10206                                                                                         }
10207                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10208                                                                                                 if(numplayers>1)
10209                                                                                                         for(j=0;j<numplayers;j++){
10210                                                                                                                 if(player[i].weaponactive==-1)
10211                                                                                                                         if(j!=i)
10212                                                                                                                                 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)){
10213                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
10214                                                                                                                                                 player[i].throwtogglekeydown=1;
10215                                                                                                                                                 player[i].victim=&player[j];
10216                                                                                                                                                 player[i].hasvictim=1;
10217                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10218                                                                                                                                                 player[i].target=0;
10219                                                                                                                                                 player[i].targetframe=0;
10220                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10221                                                                                                                                                 Normalise(&rotatetarget);
10222                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10223                                                                                                                                                 player[i].targetrotation*=360/6.28;
10224                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10225                                                                                                                                         }
10226                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10227                                                                                                                                                 player[i].throwtogglekeydown=1;
10228                                                                                                                                                 player[i].victim=&player[j];
10229                                                                                                                                                 player[i].hasvictim=1;
10230                                                                                                                                                 int k = player[j].weaponids[0];
10231                                                                                                                                                 if(player[i].hasvictim){
10232                                                                                                                                                         float gLoc[3];
10233                                                                                                                                                         float vel[3];
10234                                                                                                                                                         gLoc[0]=player[i].coords.x;
10235                                                                                                                                                         gLoc[1]=player[i].coords.y;
10236                                                                                                                                                         gLoc[2]=player[i].coords.z;
10237                                                                                                                                                         vel[0]=player[i].velocity.x;
10238                                                                                                                                                         vel[1]=player[i].velocity.y;
10239                                                                                                                                                         vel[2]=player[i].velocity.z;
10240                                                                                                                                                         bool fleshstuck;
10241                                                                                                                                                         fleshstuck=0;
10242                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
10243                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10244                                                                                                                                                                         fleshstuck=1;
10245                                                                                                                                                                 }
10246                                                                                                                                                         }
10247                                                                                                                                                         if(!fleshstuck){
10248                                                                                                                                                                 if(weapons.type[k]!=staff){
10249                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10250                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10251                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10252                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], false);
10253                                                                                                                                                                 }
10254                                                                                                                                                         }
10255                                                                                                                                                         if(fleshstuck){
10256                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
10257                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
10258                                                                                                                                                                 FSOUND_SetVolume(channels[fleshstabremovesound], 128);
10259                                                                                                                                                                 FSOUND_SetPaused(channels[fleshstabremovesound], false);
10260                                                                                                                                                         }
10261
10262                                                                                                                                                         player[i].weaponactive=0;
10263                                                                                                                                                         if(weapons.owner[k]!=-1){
10264                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
10265                                                                                                                                                                 else player[i].victim->num_weapons=1;
10266
10267                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
10268                                                                                                                                                                 player[i].victim->skeleton.free=1;
10269                                                                                                                                                                 player[i].victim->skeleton.broken=0;
10270
10271                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
10272                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
10273                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
10274                                                                                                                                                                 }
10275
10276                                                                                                                                                                 XYZ relative;
10277                                                                                                                                                                 relative=0;
10278                                                                                                                                                                 relative.y=10;
10279                                                                                                                                                                 Normalise(&relative);
10280                                                                                                                                                                 XYZ footvel,footpoint;
10281                                                                                                                                                                 footvel=0;
10282                                                                                                                                                                 footpoint=weapons.position[k];
10283                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
10284                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10285                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
10286                                                                                                                                                                                 weapons.bloody[k]=2;
10287                                                                                                                                                                                 weapons.blooddrip[k]=5;
10288                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
10289                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
10290                                                                                                                                                                                 player[i].victim->DoDamage(2000);
10291                                                                                                                                                                         }
10292                                                                                                                                                                 }
10293                                                                                                                                                                 if(player[i].victim->num_weapons>0){
10294                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
10295                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
10296                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
10297                                                                                                                                                                 }
10298
10299                                                                                                                                                                 player[i].victim->weaponactive=-1;
10300
10301                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
10302                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
10303                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
10304                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
10305                                                                                                                                                         }
10306                                                                                                                                                         weapons.owner[k]=i;
10307                                                                                                                                                         if(player[i].num_weapons>0){
10308                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10309                                                                                                                                                         }
10310                                                                                                                                                         player[i].num_weapons++;
10311                                                                                                                                                         player[i].weaponids[0]=k;
10312                                                                                                                                                 }
10313                                                                                                                                         }
10314                                                                                                                                 }
10315                                                                                                         }
10316                                                                                         }
10317                                                                                 }
10318                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10319                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
10320                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
10321                                                                                                         if(numplayers>1)
10322                                                                                                                 for(j=0;j<numplayers;j++){
10323                                                                                                                         if(i!=j)
10324                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
10325                                                                                                                                         if(hostile)
10326                                                                                                                                                 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)){
10327                                                                                                                                                         if(!player[i].isFlip()){
10328                                                                                                                                                                 player[i].throwtogglekeydown=1;
10329                                                                                                                                                                 player[i].victim=&player[j];
10330                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10331                                                                                                                                                                 player[i].target=0;
10332                                                                                                                                                                 player[i].targetframe=0;
10333                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10334                                                                                                                                                                 Normalise(&rotatetarget);
10335                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10336                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10337                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10338
10339                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10340                                                                                                                                                         }
10341                                                                                                                                                         if(player[i].isFlip()){
10342                                                                                                                                                                 if(player[i].weaponactive!=-1){
10343                                                                                                                                                                         player[i].throwtogglekeydown=1;
10344                                                                                                                                                                         player[i].victim=&player[j];
10345                                                                                                                                                                         XYZ aim;
10346                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10347                                                                                                                                                                         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);
10348                                                                                                                                                                         Normalise(&aim);
10349
10350                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10351
10352                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10353                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10354                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10355                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10356                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10357                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10358                                                                                                                                                                         player[i].num_weapons--;
10359                                                                                                                                                                         if(player[i].num_weapons){
10360                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10361                                                                                                                                                                         }
10362                                                                                                                                                                         player[i].weaponactive=-1;
10363                                                                                                                                                                 }
10364                                                                                                                                                         }
10365                                                                                                                                                 }
10366                                                                                                                 }
10367                                                                                         }
10368                                                                                 }
10369                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10370                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10371                                                                                         {
10372                                                                                                 player[i].throwtogglekeydown=1;
10373                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10374                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10375                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10376                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10377                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10378                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10379                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10380                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10381                                                                                                 player[i].num_weapons--;
10382                                                                                                 if(player[i].num_weapons){
10383                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10384                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10385                                                                                                 }
10386
10387                                                                                                 player[i].weaponactive=-1;
10388                                                                                                 for(j=0;j<numplayers;j++){
10389                                                                                                         player[j].wentforweapon=0;
10390                                                                                                 }
10391                                                                                         }
10392                                                                                 }
10393
10394                                                                         }
10395
10396                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10397                                                                                 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)){
10398                                                                                         //Setenvironment(1-environment);
10399                                                                                         bool isgood;
10400                                                                                         isgood=1;
10401                                                                                         if(player[i].weaponactive!=-1){
10402                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10403                                                                                         }
10404                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10405                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10406                                                                                                         player[i].targetanimation=drawrightanim;
10407                                                                                                         player[i].targetframe=0;
10408                                                                                                         player[i].target=0;
10409                                                                                                         player[i].drawtogglekeydown=1;
10410                                                                                                 }
10411                                                                                                 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){
10412                                                                                                         player[i].targetanimation=drawleftanim;
10413                                                                                                         player[i].targetframe=0;
10414                                                                                                         player[i].target=0;
10415                                                                                                         player[i].drawtogglekeydown=1;
10416                                                                                                 }
10417                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10418                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10419                                                                                                         player[i].targetframe=0;
10420                                                                                                         player[i].target=0;
10421                                                                                                         player[i].drawtogglekeydown=1;
10422                                                                                                 }
10423                                                                                         }
10424                                                                                 }
10425                                                                                 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){
10426                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10427                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10428                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10429                                                                                                 player[i].targetframe=0;
10430                                                                                                 player[i].target=0;
10431                                                                                                 player[i].hasvictim=0;
10432                                                                                                 //player[i].attacktogglekeydown=1;
10433                                                                                         }
10434                                                                                 }
10435
10436                                                                                 if(!player[i].drawkeydown){
10437                                                                                         player[i].drawtogglekeydown=0;
10438                                                                                 }
10439
10440                                                                                 if(i==0){
10441                                                                                         absflatfacing=0;
10442                                                                                         absflatfacing.z=-1;
10443
10444                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10445                                                                                 }
10446                                                                                 else absflatfacing=flatfacing;
10447
10448                                                                                 if(indialogue!=-1){
10449                                                                                         player[i].forwardkeydown=0;
10450                                                                                         player[i].leftkeydown=0;
10451                                                                                         player[i].backkeydown=0;
10452                                                                                         player[i].rightkeydown=0;
10453                                                                                         player[i].jumpkeydown=0;
10454                                                                                         player[i].crouchkeydown=0;
10455                                                                                         player[i].drawkeydown=0;
10456                                                                                         player[i].throwkeydown=0;
10457                                                                                 }
10458                                                                                 movekey=0;
10459                                                                                 //Do controls
10460                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10461                                                                                         if(!player[i].forwardkeydown){
10462                                                                                                 player[i].forwardstogglekeydown=0;
10463                                                                                         }
10464                                                                                         if(player[i].crouchkeydown){
10465                                                                                                 //Crouch
10466                                                                                                 target=-2;
10467                                                                                                 if(i==0){
10468                                                                                                         player[i].superruntoggle=1;
10469                                                                                                         if(numplayers>1)
10470                                                                                                                 for(j=0;j<numplayers;j++){
10471                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10472                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10473                                                                                                                                         player[i].superruntoggle=0;
10474                                                                                                                                 }
10475                                                                                                                         }
10476                                                                                                                 }
10477                                                                                                 }
10478
10479                                                                                                 if(numplayers>1)
10480                                                                                                         for(j=0;j<numplayers;j++){
10481                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10482                                                                                                                         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))){
10483                                                                                                                                 if(target>=0)target=-1;
10484                                                                                                                                 else target=j;
10485                                                                                                                         }
10486                                                                                                                 }
10487                                                                                                         }
10488                                                                                                         if(target>=0)player[target].Reverse();
10489                                                                                                         player[i].lowreversaldelay=.5;
10490
10491                                                                                                         if(player[i].isIdle()){
10492                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10493                                                                                                                 player[i].target=0;
10494                                                                                                                 player[i].targetframe=0;
10495                                                                                                                 player[i].transspeed=10;
10496                                                                                                         }
10497                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10498                                                                                                                 player[i].targetanimation=rollanim;
10499                                                                                                                 player[i].target=0;
10500                                                                                                                 player[i].targetframe=0;
10501                                                                                                                 player[i].transspeed=20;
10502                                                                                                         }
10503                                                                                         }
10504                                                                                         if(!player[i].crouchkeydown){
10505                                                                                                 //Uncrouch
10506                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10507                                                                                                 target=-2;
10508                                                                                                 if(player[i].isCrouch()){
10509                                                                                                         if(numplayers>1)
10510                                                                                                                 for(j=0;j<numplayers;j++){
10511                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10512                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10513                                                                                                                                         if(target>=0)target=-1;
10514                                                                                                                                         else target=j;
10515                                                                                                                                 }
10516                                                                                                                         }
10517                                                                                                                 }
10518                                                                                                                 if(target>=0)player[target].Reverse();
10519                                                                                                                 player[i].highreversaldelay=.5;
10520
10521                                                                                                                 if(player[i].isCrouch()){
10522                                                                                                                         if(!player[i].wasCrouch()){
10523                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10524                                                                                                                                 player[i].currentframe=0;
10525                                                                                                                         }
10526                                                                                                                         player[i].target=0;
10527                                                                                                                         player[i].targetanimation=player[i].getIdle();
10528                                                                                                                         player[i].targetframe=0;
10529                                                                                                                         player[i].transspeed=10;
10530                                                                                                                 }
10531                                                                                                 }
10532                                                                                                 if(player[i].targetanimation==sneakanim){
10533                                                                                                         player[i].targetanimation=player[i].getIdle();
10534                                                                                                         player[i].target=0;
10535                                                                                                         player[i].targetframe=0;
10536                                                                                                         player[i].transspeed=10;
10537                                                                                                 }
10538                                                                                         }
10539                                                                                         if(player[i].forwardkeydown){
10540                                                                                                 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)){
10541                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10542                                                                                                         else player[i].targetanimation=player[i].getRun();
10543                                                                                                         player[i].target=0;
10544                                                                                                         player[i].targetframe=0;
10545                                                                                                 }
10546                                                                                                 if(player[i].isCrouch()){
10547                                                                                                         player[i].targetanimation=sneakanim;
10548                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10549                                                                                                         player[i].targetframe=0;
10550                                                                                                 }
10551                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10552                                                                                                         player[i].targetanimation=climbanim;
10553                                                                                                         player[i].target=0;
10554                                                                                                         player[i].targetframe=1;
10555                                                                                                         player[i].jumpclimb=1;
10556                                                                                                 }
10557                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10558                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10559                                                                                                 }
10560                                                                                                 player[i].forwardstogglekeydown=1;
10561                                                                                                 movekey=1;
10562                                                                                         }
10563                                                                                         if (player[i].rightkeydown){
10564                                                                                                 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)){
10565                                                                                                         player[i].targetanimation=player[i].getRun();
10566                                                                                                         player[i].target=0;
10567                                                                                                         player[i].targetframe=0;
10568                                                                                                 }
10569                                                                                                 if(player[i].isCrouch()){
10570                                                                                                         player[i].targetanimation=sneakanim;
10571                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10572                                                                                                         player[i].targetframe=0;
10573                                                                                                 }
10574                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10575                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10576                                                                                                 }
10577                                                                                                 player[i].targetrotation-=90;
10578                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10579                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10580                                                                                                 movekey=1;
10581                                                                                         }
10582                                                                                         if ( player[i].leftkeydown){
10583                                                                                                 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)){
10584                                                                                                         player[i].targetanimation=player[i].getRun();
10585                                                                                                         player[i].target=0;
10586                                                                                                         player[i].targetframe=0;
10587                                                                                                 }
10588                                                                                                 if(player[i].isCrouch()){
10589                                                                                                         player[i].targetanimation=sneakanim;
10590                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10591                                                                                                         player[i].targetframe=0;
10592                                                                                                 }
10593                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10594                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10595                                                                                                 }
10596                                                                                                 player[i].targetrotation+=90;
10597                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10598                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10599                                                                                                 movekey=1;
10600                                                                                         }
10601                                                                                         if(player[i].backkeydown){
10602                                                                                                 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)){
10603                                                                                                         player[i].targetanimation=player[i].getRun();
10604                                                                                                         player[i].target=0;
10605                                                                                                         player[i].targetframe=0;
10606                                                                                                 }
10607                                                                                                 if(player[i].isCrouch()){
10608                                                                                                         player[i].targetanimation=sneakanim;
10609                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10610                                                                                                         player[i].targetframe=0;
10611                                                                                                 }
10612                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10613                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10614                                                                                                 }
10615                                                                                                 if(player[i].targetanimation==hanganim){
10616                                                                                                         player[i].currentanimation=jumpdownanim;
10617                                                                                                         player[i].targetanimation=jumpdownanim;
10618                                                                                                         player[i].target=0;
10619                                                                                                         player[i].currentframe=0;
10620                                                                                                         player[i].targetframe=1;
10621                                                                                                         player[i].velocity=0;
10622                                                                                                         player[i].velocity.y+=gravity;
10623                                                                                                         player[i].coords.y-=1.4;
10624                                                                                                         player[i].grabdelay=1;
10625                                                                                                 }
10626                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10627                                                                                                         player[i].targetrotation+=180;
10628                                                                                                 movekey=1;
10629                                                                                         }
10630                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10631                                                                                                 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)){
10632                                                                                                         player[i].jumpstart=0;
10633                                                                                                         player[i].targetanimation=jumpupanim;
10634                                                                                                         player[i].target=0;
10635                                                                                                         player[i].targetframe=0;
10636                                                                                                         player[i].rotation=player[i].targetrotation;
10637                                                                                                         player[i].transspeed=20;
10638                                                                                                         player[i].FootLand(0,1);
10639                                                                                                         player[i].FootLand(1,1);
10640
10641                                                                                                         facing=0;
10642                                                                                                         facing.z=-1;
10643                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10644
10645                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10646                                                                                                         if(!movekey)player[i].velocity=0;
10647
10648                                                                                                         //Dodge sweep?
10649                                                                                                         target=-2;
10650                                                                                                         if(numplayers>1)
10651                                                                                                                 for(j=0;j<numplayers;j++){
10652                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10653                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10654                                                                                                                                         if(target>=0)target=-1;
10655                                                                                                                                         else target=j;
10656                                                                                                                                 }
10657                                                                                                                         }
10658                                                                                                                 }
10659                                                                                                                 if(target>=0)player[i].velocity.y=1;
10660                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10661                                                                                                                         player[i].velocity.y=7;
10662                                                                                                                         player[i].crouchtogglekeydown=1;
10663                                                                                                                 }
10664                                                                                                                 else player[i].velocity.y=5;
10665
10666                                                                                                                 if(mousejump&&i==0&&debugmode){
10667                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10668                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10669                                                                                                                 }
10670
10671                                                                                                                 player[i].coords.y+=.2;
10672                                                                                                                 player[i].jumppower-=1;
10673
10674                                                                                                                 static float gLoc[3];
10675                                                                                                                 static float vel[3];
10676                                                                                                                 gLoc[0]=player[i].coords.x;
10677                                                                                                                 gLoc[1]=player[i].coords.y;
10678                                                                                                                 gLoc[2]=player[i].coords.z;
10679                                                                                                                 vel[0]=player[i].velocity.x;
10680                                                                                                                 vel[1]=player[i].velocity.y;
10681                                                                                                                 vel[2]=player[i].velocity.z;
10682
10683                                                                                                                 if(i==0){
10684                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
10685                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10686                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
10687                                                                                                                         FSOUND_SetPaused(channels[whooshsound], false);
10688                                                                                                                 }
10689
10690                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
10691                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10692                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
10693                                                                                                                 FSOUND_SetPaused(channels[jumpsound], false);
10694                                                                                                 }
10695                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10696                                                                                                         player[i].targetanimation=player[i].getLanding();
10697                                                                                                         player[i].landhard=0;
10698                                                                                                         player[i].target=0;
10699                                                                                                         player[i].targetframe=2;
10700                                                                                                         player[i].jumpstart=1;
10701                                                                                                         player[i].tempdeltav=deltav;
10702                                                                                                 }
10703                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10704                                                                                                         if(player[i].jumppower>multiplier*6){
10705                                                                                                                 player[i].velocity.y+=multiplier*6;
10706                                                                                                                 player[i].jumppower-=multiplier*6;
10707                                                                                                         }
10708                                                                                                         if(player[i].jumppower<=multiplier*6){
10709                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10710                                                                                                                 player[i].jumppower=0;
10711                                                                                                         }
10712                                                                                                 }
10713                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
10714                                                                                         }
10715
10716                                                                                         if(!movekey){
10717                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10718                                                                                                         player[i].targetanimation=player[i].getStop();
10719                                                                                                         player[i].target=0;
10720                                                                                                         player[i].targetframe=0;
10721                                                                                                 }
10722                                                                                                 if(player[i].targetanimation==sneakanim){
10723                                                                                                         player[i].targetanimation=player[i].getCrouch();
10724                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10725                                                                                                         player[i].targetframe=0;
10726                                                                                                 }
10727                                                                                         }
10728                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10729                                                                                                 player[i].targetanimation=player[i].getStop();
10730                                                                                                 player[i].target=0;
10731                                                                                                 player[i].targetframe=0;
10732                                                                                         }
10733                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10734                                                                                                 player[i].targetanimation=player[i].getStop();
10735                                                                                                 player[i].target=0;
10736                                                                                                 player[i].targetframe=0;
10737                                                                                         }
10738                                                                                 }
10739                                                                 }
10740                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10741                                                         }
10742
10743                                                         //Rotation
10744                                                         for(k=0;k<numplayers;k++){
10745                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10746                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10747                                                                         else player[k].rotation+=360;
10748                                                                 }
10749
10750                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10751                                                                         player[k].targetanimation=player[k].getStop();
10752                                                                         player[k].targetframe=0;
10753                                                                         player[k].target=0;
10754                                                                 }
10755
10756                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10757                                                                         player[k].targettilt=0;
10758                                                                 }
10759                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10760                                                                         player[k].targettilt=0;
10761                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10762                                                                         player[k].jumppower+=multiplier*7;
10763                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10764                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10765                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10766                                                                 }
10767
10768                                                                 if(player[k].isRun()){
10769                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10770                                                                 }
10771
10772                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10773                                                                 else if(player[k].tilt>player[k].targettilt){
10774                                                                         player[k].tilt-=multiplier*150;
10775                                                                 }
10776                                                                 else if(player[k].tilt<player[k].targettilt){
10777                                                                         player[k].tilt+=multiplier*150;
10778                                                                 }
10779
10780                                                                 player[k].grabdelay-=multiplier;
10781                                                         }
10782
10783                                                         for(k=0;k<numplayers;k++){
10784                                                                 player[k].DoAnimations();
10785                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10786                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10787                                                         }
10788
10789                                                         objects.DoStuff();
10790                                                         /*
10791                                                         player[0].righthandmorphstart=0;
10792                                                         player[0].righthandmorphend=1;
10793                                                         player[0].lefthandmorphstart=0;
10794                                                         player[0].lefthandmorphend=1;
10795                                                         player[0].headmorphstart=0;
10796                                                         player[0].headmorphend=2;*/
10797
10798                                                         /*
10799                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10800                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10801                                                         player[0].righthandmorphend=1;
10802                                                         player[0].targetrighthandmorphness=1;
10803
10804                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10805                                                         player[0].lefthandmorphend=0;
10806                                                         player[0].targetlefthandmorphness=1;
10807
10808                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10809                                                         player[0].headmorphend=2;
10810                                                         player[0].targetheadmorphness=1;
10811                                                         }
10812                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10813                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10814                                                         player[0].righthandmorphend=0;
10815                                                         player[0].targetrighthandmorphness=1;
10816
10817                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10818                                                         player[0].lefthandmorphend=1;
10819                                                         player[0].targetlefthandmorphness=1;
10820
10821                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10822                                                         player[0].headmorphend=0;
10823                                                         player[0].targetheadmorphness=1;
10824                                                         }
10825                                                         */
10826                                                         if(numenvsounds!=0)
10827                                                                 for(j=numenvsounds-1;j>=0;j--){
10828                                                                         envsoundlife[j]-=multiplier;
10829                                                                         if(envsoundlife[j]<0){
10830                                                                                 numenvsounds--;
10831                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10832                                                                                 envsound[j]=envsound[numenvsounds];
10833                                                                         }
10834                                                                 }
10835                                                                 if(!slomo)FSOUND_SetFrequency(FSOUND_ALL, 22050);
10836                                                                 if(slomo)FSOUND_SetFrequency(FSOUND_ALL, slomofreq);
10837
10838                                                                 if(tutoriallevel==1){
10839                                                                         XYZ temp;
10840                                                                         XYZ temp2;
10841                                                                         XYZ temp3;
10842                                                                         XYZ oldtemp;
10843                                                                         XYZ oldtemp2;
10844                                                                         temp.x=1011;
10845                                                                         temp.y=84;
10846                                                                         temp.z=491;
10847                                                                         temp2.x=1025;
10848                                                                         temp2.y=75;
10849                                                                         temp2.z=447;
10850                                                                         temp3.x=1038;
10851                                                                         temp3.y=76;
10852                                                                         temp3.z=453;
10853                                                                         oldtemp=temp;
10854                                                                         oldtemp2=temp2;
10855                                                                         if(tutorialstage>=51)
10856                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10857                                                     FSOUND_StopSound(FSOUND_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
10858                                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
10859
10860                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10861                                                                                         FSOUND_SetPaused(channels[stream_music3], false);
10862                                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
10863
10864                                                                                         gameon=0;
10865                                                                                         mainmenu=5;
10866
10867                                                                                         float gLoc[3]={0,0,0};
10868                                                                                         float vel[3]={0,0,0};
10869                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10870                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10871                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10872                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10873                                                                                         FSOUND_SetPaused(channels[fireendsound], false);
10874                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10875
10876                                                                                         flashr=1;
10877                                                                                         flashg=0;
10878                                                                                         flashb=0;
10879                                                                                         flashamount=1;
10880                                                                                         flashdelay=1;
10881                                                                                 }
10882                                                                                 if(tutorialstage<51)
10883                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10884                                                                                                 float gLoc[3];
10885                                                                                                 float vel[3];
10886                                                                                                 gLoc[0]=player[0].coords.x;
10887                                                                                                 gLoc[1]=player[0].coords.y;
10888                                                                                                 gLoc[2]=player[0].coords.z;
10889                                                                                                 vel[0]=0;
10890                                                                                                 vel[1]=0;
10891                                                                                                 vel[2]=0;
10892                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10893                                                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10894                                                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
10895                                                                                                 FSOUND_SetPaused(channels[fireendsound], false);
10896
10897                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10898
10899                                                                                                 flashr=1;
10900                                                                                                 flashg=1;
10901                                                                                                 flashb=1;
10902                                                                                                 flashamount=1;
10903                                                                                                 flashdelay=1;
10904                                                                                         }
10905                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10906                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10907                                                                                                         float gLoc[3];
10908                                                                                                         float vel[3];
10909                                                                                                         gLoc[0]=player[1].coords.x;
10910                                                                                                         gLoc[1]=player[1].coords.y;
10911                                                                                                         gLoc[2]=player[1].coords.z;
10912                                                                                                         vel[0]=0;
10913                                                                                                         vel[1]=0;
10914                                                                                                         vel[2]=0;
10915                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10916                                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10917                                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10918                                                                                                         FSOUND_SetPaused(channels[fireendsound], false);
10919
10920                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10921                                                                                                                 if(Random()%2==0){
10922                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10923                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10924                                                                                                                         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;
10925                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10926                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10927                                                                                                                 }
10928                                                                                                         }
10929
10930                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10931                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10932                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10933                                                                                                                 if(Random()%2==0){
10934                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10935                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10936                                                                                                                         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;
10937                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10938                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10939                                                                                                                 }
10940                                                                                                         }
10941                                                                                                 }
10942                                                                 }
10943
10944
10945                                                                 //3d sound
10946                                                                 static float gLoc[3];
10947                                                                 gLoc[0]=viewer.x;
10948                                                                 gLoc[1]=viewer.y;
10949                                                                 gLoc[2]=viewer.z;
10950                                                                 static float vel[3];
10951                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10952                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10953                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10954
10955                                                                 //Set orientation with forward and up vectors
10956                                                                 static XYZ upvector;
10957                                                                 upvector=0;
10958                                                                 upvector.z=-1;
10959
10960                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10961                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10962
10963                                                                 facing=0;
10964                                                                 facing.z=-1;
10965
10966                                                                 facing=DoRotation(facing,-rotation2,0,0);
10967                                                                 facing=DoRotation(facing,0,0-rotation,0);
10968
10969
10970                                                                 static float ori[6];
10971                                                                 ori[0] = -facing.x;
10972                                                                 ori[1] = facing.y;
10973                                                                 ori[2] = -facing.z;
10974                                                                 ori[3] = -upvector.x;
10975                                                                 ori[4] = upvector.y;
10976                                                                 ori[5] = -upvector.z;
10977
10978                                                                 FSOUND_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10979                                                                 FSOUND_Update();
10980
10981                                                                 oldviewer=viewer;
10982                 }
10983         }
10984
10985         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10986                 Screenshot();
10987                 freezetogglekeydown=1;
10988         }
10989 }
10990
10991 void    Game::TickOnce(){
10992         //if(!console){
10993         if(!mainmenu)
10994                 if(directing||indialogue==-1){
10995                         rotation+=deltah*.7;
10996                         if(!invertmouse)rotation2+=deltav*.7;
10997                         if(invertmouse)rotation2-=deltav*.7;
10998                         if(rotation2>90)rotation2=90;
10999                         if(rotation2<-70)rotation2=-70;
11000                 }
11001                 if(mainmenu)rotation+=multiplier*5;
11002                 if(!mainmenu&&!indemo&&!registered){
11003                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
11004                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11005                         FSOUND_SetPaused(channels[stream_music3], false);
11006                         FSOUND_SetVolume(channels[stream_music3], 256);
11007
11008                         gameon=0;
11009                         mainmenu=12;
11010
11011                         float gLoc[3]={0,0,0};
11012                         float vel[3]={0,0,0};
11013                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11014                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11015                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11016                         FSOUND_SetVolume(channels[fireendsound], 256);
11017                         FSOUND_SetPaused(channels[fireendsound], false);
11018                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11019
11020                         flashr=1;
11021                         flashg=0;
11022                         flashb=0;
11023                         flashamount=1;
11024                         flashdelay=1;
11025                 }
11026
11027                 if(tryquit==1&&!registered&&mainmenu!=12){
11028                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
11029                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11030                         FSOUND_SetPaused(channels[stream_music3], false);
11031                         FSOUND_SetVolume(channels[stream_music3], 256);
11032
11033                         gameon=0;
11034                         mainmenu=12;
11035
11036                         float gLoc[3]={0,0,0};
11037                         float vel[3]={0,0,0};
11038                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11039                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11040                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11041                         FSOUND_SetVolume(channels[fireendsound], 256);
11042                         FSOUND_SetPaused(channels[fireendsound], false);
11043                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11044
11045                         flashr=1;
11046                         flashg=0;
11047                         flashb=0;
11048                         flashamount=1;
11049                         flashdelay=1;
11050                 }
11051                 //}
11052 }
11053
11054 void    Game::TickOnceAfter(){
11055         static XYZ colviewer;
11056         static XYZ coltarget;
11057         static XYZ target;
11058         static XYZ col;
11059         static float brotate;
11060         static XYZ facing;
11061         static int i,j;
11062         static float changedelay;
11063         static bool alldead;
11064         static float unseendelay;
11065         static float cameraspeed;
11066
11067         if(!mainmenu){
11068
11069                 if(environment==snowyenvironment)music1=stream_music1snow;
11070                 if(environment==grassyenvironment)music1=stream_music1grass;
11071                 if(environment==desertenvironment)music1=stream_music1desert;
11072
11073                 realthreat=0;
11074
11075                 musictype=music1;
11076                 for(i=0;i<numplayers;i++){
11077                         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)){
11078                                 musictype=stream_music2;
11079                                 realthreat=1;
11080                         }
11081                 }
11082                 if(player[0].dead)musictype=stream_music3;
11083
11084
11085                 if(musictype==stream_music2){
11086                         unseendelay=1;
11087                 }
11088
11089                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
11090                         unseendelay-=multiplier;
11091                         if(unseendelay>0){
11092                                 musictype=stream_music2;
11093                         }
11094                 }
11095
11096
11097                 if(loading==2){
11098                         musictype=stream_music3;
11099                         musicvolume[2]=512;
11100                         musicvolume[0]=0;
11101                         musicvolume[1]=0;
11102                         musicvolume[3]=0;
11103                 }
11104
11105                 if(musictoggle){
11106                         if(musictype!=oldmusictype&&musictype==stream_music2){
11107                                 static float gLoc[3];
11108                                 static float vel[3];
11109                                 gLoc[0]=cameraloc.x;
11110                                 gLoc[1]=cameraloc.y;
11111                                 gLoc[2]=cameraloc.z;
11112                                 vel[0]=0;
11113                                 vel[1]=0;
11114                                 vel[2]=0;
11115                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
11116                                 FSOUND_SetVolume(channels[alarmsound], 512);
11117                                 FSOUND_SetPaused(channels[alarmsound], false);
11118
11119                         }
11120                 }
11121                 musicselected=musictype;
11122
11123                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
11124                 else musicvolume[0]-=multiplier*450;
11125                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
11126                 else musicvolume[1]-=multiplier*450;
11127                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
11128                 else musicvolume[2]-=multiplier*450;
11129                 /*
11130                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
11131                 else musicvolume[0]-=multiplier*450;
11132                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
11133                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
11134                 else musicvolume[1]-=multiplier*100;
11135                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
11136                 else musicvolume[2]-=multiplier*450;*/
11137
11138                 for(i=0;i<3;i++){
11139                         if(musicvolume[i]<0)musicvolume[i]=0;
11140                         if(musicvolume[i]>512)musicvolume[i]=512;
11141                 }
11142
11143                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
11144
11145                 if(musictoggle){
11146                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
11147                                 PlayStreamEx( music1, strm[music1], NULL, true);
11148                                 FSOUND_SetPaused(channels[music1], false);
11149                         }
11150                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
11151                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
11152                                 FSOUND_SetPaused(channels[stream_music2], false);
11153                         }
11154                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
11155                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11156                                 FSOUND_SetPaused(channels[stream_music3], false);
11157                         }
11158                 }
11159
11160                 if(!musictoggle){
11161                         FSOUND_SetPaused(channels[music1], true);
11162                         FSOUND_SetPaused(channels[stream_music2], true);
11163                         FSOUND_SetPaused(channels[stream_music3], true);
11164
11165                         for(i=0;i<4;i++){
11166                                 oldmusicvolume[i]=0;
11167                                 musicvolume[i]=0;
11168                         }
11169                 }
11170
11171                 if(musictoggle){
11172                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
11173                                 FSOUND_SetPaused(channels[music1], true);
11174                         }
11175                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
11176                                 FSOUND_SetPaused(channels[stream_music2], true);
11177                         }
11178                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
11179                                 FSOUND_SetPaused(channels[stream_music3], true);
11180                         }
11181
11182                         if(musicvolume[0]!=oldmusicvolume[0]){
11183                                 FSOUND_SetVolume(channels[music1], musicvolume[0]);
11184                         }
11185                         if(musicvolume[1]!=oldmusicvolume[1]){
11186                                 FSOUND_SetVolume(channels[stream_music2], musicvolume[1]);
11187                         }
11188                         if(musicvolume[2]!=oldmusicvolume[2]){
11189                                 FSOUND_SetVolume(channels[stream_music3], musicvolume[2]);
11190                         }
11191
11192                         for(i=0;i<3;i++){
11193                                 oldmusicvolume[i]=musicvolume[i];
11194                         }
11195                 }
11196
11197                 killhotspot=2;
11198                 if(numhotspots)
11199                         for(i=0;i<numhotspots;i++){
11200                                 if(hotspottype[i]>10&&hotspottype[i]<20){
11201                                         if(player[hotspottype[i]-10].dead==0){
11202                                                 killhotspot=0;
11203                                         }
11204                                         else if(killhotspot==2)
11205                                                 killhotspot=1;
11206                                 }
11207                         }
11208                         if(killhotspot==2)killhotspot=0;
11209
11210
11211                         winhotspot=0;
11212                         if(numhotspots)
11213                                 for(i=0;i<numhotspots;i++){
11214                                         if(hotspottype[i]==-1){
11215                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
11216                                                         winhotspot=1;
11217                                         }
11218                                 }
11219
11220                                 int numalarmed=0;
11221                                 if(numplayers>1)
11222                                         for(i=1;i<numplayers;i++){
11223                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
11224                                         }
11225                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
11226
11227                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
11228                                                 if(player[0].dead&&changedelay<=0){
11229                                                         changedelay=1;
11230                                                         targetlevel=whichlevel;
11231                                                 }
11232                                                 alldead=1;
11233                                                 if(numplayers>1)
11234                                                         for(i=1;i<numplayers;i++){
11235                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
11236                                                         }
11237
11238
11239                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
11240                                                                 changedelay=1;
11241                                                                 targetlevel=whichlevel+1;
11242                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11243                                                         }
11244                                                         if(winhotspot||windialogue){
11245                                                                 changedelay=0.1;
11246                                                                 targetlevel=whichlevel+1;
11247                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11248                                                         }
11249
11250
11251                                                         if(killhotspot){
11252                                                                 changedelay=1;
11253                                                                 targetlevel=whichlevel+1;
11254                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11255                                                         }
11256
11257                                                         if(changedelay>0&&!player[0].dead&&!won){
11258                                                                 //high scores, awards, win
11259                                                                 if(campaign){
11260                                                                         won=1;
11261                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11262                                                                         accountcampaignchoicesmade[accountactive]++;
11263                                                                         accountcampaignscore[accountactive]+=bonustotal;
11264                                                                         scoreadded=1;
11265                                                                         accountcampaigntime[accountactive]+=leveltime;
11266                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
11267
11268                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11269                                                                 }
11270                                                                 else
11271                                                                 {
11272                                                                         won=1;
11273                                                                         if(!debugmode){
11274                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
11275                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;
11276                                                                         }
11277                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11278
11279                                                                 }
11280                                                         }
11281                                         }
11282
11283                                         if(!winfreeze){
11284
11285                                                 if(leveltime<1){
11286                                                         loading=0;
11287                                                         changedelay=.1;
11288                                                         alldead=0;
11289                                                         winhotspot=0;
11290                                                         killhotspot=0;
11291                                                 }
11292
11293                                                 if(!editorenabled&&gameon&&!mainmenu){
11294                                                         if(changedelay!=-999)changedelay-=multiplier/7;
11295                                                         if(player[0].dead)targetlevel=whichlevel;
11296                                                         if(loading==2&&!campaign){
11297                                                                 flashr=1;
11298                                                                 flashg=0;
11299                                                                 flashb=0;
11300                                                                 flashamount=1;
11301                                                                 flashdelay=1;
11302                                                                 loadtime=0;
11303
11304                                                                 float gLoc[3]={0,0,0};
11305                                                                 float vel[3]={0,0,0};
11306                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11307                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11308                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11309                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11310                                                                 FSOUND_SetPaused(channels[firestartsound], false);
11311                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11312
11313                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
11314                                                                         startbonustotal=bonustotal;
11315                                                                 }
11316                                                                 if(!player[0].dead)Loadlevel(targetlevel);
11317                                                                 if(player[0].dead)Loadlevel(whichlevel);
11318
11319                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11320                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11321                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11322                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11323                                                                 FSOUND_SetPaused(channels[fireendsound], false);
11324                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11325
11326                                                                 loading=3;
11327                                                         }
11328                                                         if(loading==2&&targetlevel==whichlevel){
11329                                                                 flashr=1;
11330                                                                 flashg=0;
11331                                                                 flashb=0;
11332                                                                 flashamount=1;
11333                                                                 flashdelay=1;
11334                                                                 loadtime=0;
11335
11336                                                                 float gLoc[3]={0,0,0};
11337                                                                 float vel[3]={0,0,0};
11338                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11339                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11340                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11341                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11342                                                                 FSOUND_SetPaused(channels[firestartsound], false);
11343                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11344
11345                                                                 for(i=0;i<255;i++){
11346                                                                         mapname[i]='\0';
11347                                                                 }
11348                                                                 mapname[0]=':';
11349                                                                 mapname[1]='D';
11350                                                                 mapname[2]='a';
11351                                                                 mapname[3]='t';
11352                                                                 mapname[4]='a';
11353                                                                 mapname[5]=':';
11354                                                                 mapname[6]='M';
11355                                                                 mapname[7]='a';
11356                                                                 mapname[8]='p';
11357                                                                 mapname[9]='s';
11358                                                                 mapname[10]=':';
11359                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
11360                                                                 Loadlevel(mapname);
11361
11362                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11363                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11364                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11365                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11366                                                                 FSOUND_SetPaused(channels[fireendsound], false);
11367                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11368
11369                                                                 loading=3;
11370                                                         }
11371                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
11372                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
11373                                                                 if(accountprogress[accountactive]>3&&!registered){
11374                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
11375                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11376                                                                         FSOUND_SetPaused(channels[stream_music3], false);
11377                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
11378
11379                                                                         gameon=0;
11380                                                                         mainmenu=12;
11381                                                                         accountprogress[accountactive]=3;
11382
11383                                                                         float gLoc[3]={0,0,0};
11384                                                                         float vel[3]={0,0,0};
11385                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11386                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11387                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11388                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
11389                                                                         FSOUND_SetPaused(channels[fireendsound], false);
11390                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11391
11392                                                                         flashr=1;
11393                                                                         flashg=0;
11394                                                                         flashb=0;
11395                                                                         flashamount=1;
11396                                                                         flashdelay=1;
11397                                                                 }
11398                                                                 else{
11399                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
11400                                                                                 winfreeze=1;
11401                                                                                 changedelay=-999;
11402                                                                         }
11403                                                                         if(player[0].dead)loading=1;
11404                                                                 }
11405                                                         }
11406                                                 }
11407
11408                                                 if(campaign)
11409                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11410                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11411                                                                         endgame=1;
11412                                                                 }
11413                                                         }
11414                                                         else if(mainmenu==0&&winfreeze){
11415                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11416                                                                         stealthloading=1;
11417                                                                 else stealthloading=0;
11418
11419                                                                 if(!stealthloading){
11420                                                                         float gLoc[3]={0,0,0};
11421                                                                         float vel[3]={0,0,0};
11422                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11423                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11424                                                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11425                                                                         FSOUND_SetVolume(channels[firestartsound], 256);
11426                                                                         FSOUND_SetPaused(channels[firestartsound], false);
11427                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11428
11429                                                                         flashr=1;
11430                                                                         flashg=0;
11431                                                                         flashb=0;
11432                                                                         flashamount=1;
11433                                                                         flashdelay=1;
11434                                                                 }
11435
11436                                                                 startbonustotal=0;
11437
11438                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
11439                                                                 //campaignnumlevels=0;
11440                                                                 //accountcampaignchoicesmade[accountactive]=0;
11441                                                                 ipstream.ignore(256,':');
11442                                                                 ipstream >> campaignnumlevels;
11443                                                                 for(i=0;i<campaignnumlevels;i++){
11444                                                                         ipstream.ignore(256,':');
11445                                                                         ipstream.ignore(256,':');
11446                                                                         ipstream.ignore(256,' ');
11447                                                                         ipstream >> campaignmapname[i];
11448                                                                         ipstream.ignore(256,':');
11449                                                                         ipstream >> campaigndescription[i];
11450                                                                         for(j=0;j<256;j++){
11451                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11452                                                                         }
11453                                                                         ipstream.ignore(256,':');
11454                                                                         ipstream >> campaignchoosenext[i];
11455                                                                         ipstream.ignore(256,':');
11456                                                                         ipstream >> campaignnumnext[i];
11457                                                                         if(campaignnumnext[i])
11458                                                                                 for(j=0;j<campaignnumnext[i];j++){
11459                                                                                         ipstream.ignore(256,':');
11460                                                                                         ipstream >> campaignnextlevel[i][j];
11461                                                                                         campaignnextlevel[i][j]-=1;
11462                                                                                 }
11463                                                                                 ipstream.ignore(256,':');
11464                                                                                 ipstream >> campaignlocationx[i];
11465                                                                                 ipstream.ignore(256,':');
11466                                                                                 ipstream >> campaignlocationy[i];
11467                                                                 }
11468                                                                 ipstream.close();
11469
11470                                                                 for(i=0;i<campaignnumlevels;i++){
11471                                                                         levelvisible[i]=0;
11472                                                                         levelhighlight[i]=0;
11473                                                                 }
11474
11475
11476                                                                 for(i=0;i<campaignnumlevels;i++){
11477                                                                         levelvisible[i]=0;
11478                                                                         levelhighlight[i]=0;
11479                                                                 }
11480
11481                                                                 levelorder[0]=0;
11482                                                                 levelvisible[0]=1;
11483                                                                 if(accountcampaignchoicesmade[accountactive])
11484                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11485                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11486                                                                                 levelvisible[levelorder[i+1]]=1;
11487                                                                         }
11488                                                                         int whichlevelstart;
11489                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11490                                                                         if(whichlevelstart<0){
11491                                                                                 campaignchoicenum=1;
11492                                                                                 campaignchoicewhich[0]=0;
11493                                                                         }
11494                                                                         else
11495                                                                         {
11496                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11497                                                                                 if(campaignchoicenum)
11498                                                                                         for(i=0;i<campaignchoicenum;i++){
11499                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11500                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11501                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11502                                                                                         }
11503                                                                         }
11504
11505                                                                         loading=2;
11506                                                                         loadtime=0;
11507                                                                         targetlevel=7;
11508                                                                         //if(firstload)TickOnceAfter();
11509                                                                         if(!firstload)LoadStuff();
11510                                                                         //else {
11511                                                                         for(i=0;i<255;i++){
11512                                                                                 mapname[i]='\0';
11513                                                                         }
11514                                                                         mapname[0]=':';
11515                                                                         mapname[1]='D';
11516                                                                         mapname[2]='a';
11517                                                                         mapname[3]='t';
11518                                                                         mapname[4]='a';
11519                                                                         mapname[5]=':';
11520                                                                         mapname[6]='M';
11521                                                                         mapname[7]='a';
11522                                                                         mapname[8]='p';
11523                                                                         mapname[9]='s';
11524                                                                         mapname[10]=':';
11525
11526                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11527                                                                         //accountcampaignchoicesmade[accountactive]++;
11528
11529
11530                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11531                                                                         whichchoice=0;
11532                                                                         visibleloading=1;
11533                                                                         stillloading=1;
11534                                                                         Loadlevel(mapname);
11535                                                                         campaign=1;
11536                                                                         mainmenu=0;
11537                                                                         gameon=1;
11538                                                                         FSOUND_SetPaused(channels[stream_music3], true);
11539
11540                                                                         stealthloading=0;
11541                                                         }
11542
11543                                                         if(loading==3)loading=0;
11544
11545                                         }
11546
11547                                         oldmusictype=musictype;
11548         }
11549
11550         facing=0;
11551         facing.z=-1;
11552
11553         facing=DoRotation(facing,-rotation2,0,0);
11554         facing=DoRotation(facing,0,0-rotation,0);
11555         viewerfacing=facing;
11556
11557         brotate=0;
11558         if(!cameramode){
11559                 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;
11560                 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;
11561                 target.y+=.1;
11562                 if(player[0].skeleton.free){
11563                         for(i=0;i<player[0].skeleton.num_joints;i++){
11564                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
11565                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11566                         }
11567                         target.y+=.1;
11568                 }
11569                 if(player[0].skeleton.free!=2&&!autocam){
11570                         cameraspeed=20;
11571                         if(findLengthfast(&player[0].velocity)>400){
11572                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11573                         }
11574                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11575                         coltarget=target-cameraloc;
11576                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11577                         else {
11578                                 Normalise(&coltarget);
11579                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11580                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11581                         }
11582                         if(editorenabled)cameraloc=target;
11583                         cameradist+=multiplier*5;
11584                         if(cameradist>2.3)cameradist=2.3;
11585                         viewer=cameraloc-facing*cameradist;
11586                         colviewer=viewer;
11587                         coltarget=cameraloc;
11588                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11589                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11590                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11591                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11592                                         colviewer=viewer;
11593                                         coltarget=cameraloc;
11594                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11595                                 }
11596                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11597                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11598                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11599                                                 colviewer=viewer;
11600                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11601                                                         viewer=colviewer;
11602                                                 }
11603                                         }
11604                                         cameradist=findDistance(&viewer,&target);
11605                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11606                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11607                                         }
11608                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11609                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11610                                         }
11611                 }
11612                 if(player[0].skeleton.free!=2&&autocam){
11613                         cameraspeed=20;
11614                         if(findLengthfast(&player[0].velocity)>400){
11615                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11616                         }
11617                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11618                         cameradist+=multiplier*5;
11619                         if(cameradist>3.3)cameradist=3.3;
11620                         coltarget=target-cameraloc;
11621                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11622                         else if(findLengthfast(&coltarget)>1)
11623                         {
11624                                 Normalise(&coltarget);
11625                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11626                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11627                         }
11628                         if(editorenabled)cameraloc=target;
11629                         viewer=cameraloc;
11630                         colviewer=viewer;
11631                         coltarget=cameraloc;
11632                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11633                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11634                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11635                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11636                                         colviewer=viewer;
11637                                         coltarget=cameraloc;
11638                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11639                                 }
11640                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11641                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11642                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11643                                                 colviewer=viewer;
11644                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11645                                                         viewer=colviewer;
11646                                                 }
11647                                         }
11648                                         cameradist=findDistance(&viewer,&target);
11649                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11650                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11651                                         }
11652                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11653                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11654                                         }
11655                 }
11656                 if(camerashake>.8)camerashake=.8;
11657                 //if(woozy>10)woozy=10;
11658                 //woozy+=multiplier;
11659                 woozy+=multiplier;
11660                 if(player[0].dead)camerashake=0;
11661                 if(player[0].dead)woozy=0;
11662                 camerashake-=multiplier*2;
11663                 blackout-=multiplier*2;
11664                 //if(player[0].isCrouch())woozy-=multiplier*8;
11665                 if(camerashake<0)camerashake=0;
11666                 if(blackout<0)blackout=0;
11667                 //if(woozy<0)woozy=0;
11668                 if(camerashake){
11669                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11670                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11671                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11672                 }
11673         }
11674 }