]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
Add a pretty and desactivable damage bar.
[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 #include "openal_wrapper.h"
33
34 using namespace std;
35
36 extern float multiplier;
37 extern XYZ viewer;
38 extern int environment;
39 extern float texscale;
40 extern Terrain terrain;
41 extern OPENAL_SAMPLE    *samp[100];
42 extern int channels[100];
43 extern Sprites sprites;
44 extern int kTextureSize;
45 extern float screenwidth,screenheight;
46 extern float gravity;
47 extern int detail;
48 extern float texdetail;
49 extern Objects objects;
50 extern int slomo;
51 extern float slomodelay;
52 extern bool floatjump;
53 extern float volume;
54 extern Animation animation[animation_count];
55 extern Light light;
56 extern float texdetail;
57 extern GLubyte bloodText[512*512*3];
58 extern GLubyte wolfbloodText[512*512*3];
59 extern float terraindetail;
60 extern float camerashake;
61 extern float woozy;
62 extern float blackout;
63 extern bool cellophane;
64 extern bool musictoggle;
65 extern int difficulty;
66 extern Weapons weapons;
67 extern Person player[maxplayers];
68 extern int numplayers;
69 extern int bloodtoggle;
70 extern bool invertmouse;
71 extern float windvar;
72 extern float precipdelay;
73 extern XYZ viewerfacing;
74 extern bool ambientsound;
75 extern bool mousejump;
76 extern float viewdistance;
77 extern bool freeze;
78 extern bool autoslomo;
79 extern bool keyboardfrozen;
80 extern int netdatanew;
81 extern bool loadingstuff;
82 extern char mapname[256];
83 extern XYZ windvector;
84 extern bool buttons[3];
85 extern bool debugmode;
86 static int music1;
87 extern int mainmenu;
88 extern int oldmainmenu;
89 extern bool visibleloading;
90 extern int loadscreencolor;
91 extern float flashamount,flashr,flashg,flashb;
92 extern int flashdelay;
93 extern XYZ envsound[30];
94 extern float envsoundvol[30];
95 extern int numenvsounds;
96 extern float envsoundlife[30];
97 extern float usermousesensitivity;
98 extern bool ismotionblur;
99 extern bool foliage;
100 extern bool trilinear;
101 extern bool damageeffects;
102 extern bool showpoints;
103 extern bool showdamagebar; // (des)activate the damage bar
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
227 static const char *rabbitskin[] = {
228 ":Data:Textures:Fur3.jpg",
229 ":Data:Textures:Fur.jpg",
230 ":Data:Textures:Fur2.jpg",
231 ":Data:Textures:Lynx.jpg",
232 ":Data:Textures:Otter.jpg",
233 ":Data:Textures:Opal.jpg",
234 ":Data:Textures:Sable.jpg",
235 ":Data:Textures:Chocolate.jpg",
236 ":Data:Textures:BW2.jpg",
237 ":Data:Textures:WB2.jpg"
238 };
239
240 static const char *wolfskin[] = {
241 ":Data:Textures:Wolf.jpg",
242 ":Data:Textures:Darkwolf.jpg",
243 ":Data:Textures:Snowwolf.jpg"
244 };
245
246 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
247 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
248
249 static const char **creatureskin[] = {rabbitskin, wolfskin};
250
251 /********************> Tick() <*****/
252 extern OPENAL_STREAM * strm[20];
253 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
254 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
255
256 extern void ScreenShot(const char * fname);
257 void Screenshot (void)
258 {
259         char temp[1024];
260         time_t  t = time(NULL);
261         struct  tm *tme = localtime(&t);
262         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);
263
264         #if defined(_WIN32)
265         mkdir("Screenshots");
266         #else
267         mkdir("Screenshots", S_IRWXU);
268         #endif
269
270         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
271
272         /*FSSpec                                MAC_file;
273         GraphicsExportComponent QT_exporter;
274         OSErr                           MAC_error_code;
275         CGrafPtr                        MAC_currentPort;
276         GDHandle                        MAC_currentDevice;
277         unsigned char*          MAC_pixels;
278         Rect                            MAC_picture_rectangle;
279         GWorldPtr                       MAC_offscreen_graphics_port;
280
281         static int numscreenshots=0;
282
283         // Make an FSSpec
284         static char buf[256];
285         if(numscreenshots==0){
286         buf[0]=26;
287         buf[1]=':';
288         buf[2]='S';
289         buf[3]='c';
290         buf[4]='r';
291         buf[5]='e';
292         buf[6]='e';
293         buf[7]='n';
294         buf[8]='s';
295         buf[9]='h';
296         buf[10]='o';
297         buf[11]='t';
298         buf[12]='s';
299         buf[13]=':';
300         buf[14]='S';
301         buf[15]='c';
302         buf[16]='r';
303         buf[17]='e';
304         buf[18]='e';
305         buf[19]='n';
306         buf[20]='s';
307         buf[21]='h';
308         buf[22]='o';
309         buf[23]='t';
310         buf[24]='0';
311         buf[25]='0';
312         buf[26]='0';
313         }
314
315         FInfo *fndrInfo;
316         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
317         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
318         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
319         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
320         numscreenshots++;
321         buf[26]++;
322         if(buf[26]==':'){
323         buf[26]='0';
324         buf[25]++;
325         if(buf[25]==':'){
326         buf[25]='0';
327         buf[24]++;
328         if(buf[24]==':'){
329         buf[24]='9';
330         buf[25]='9';
331         buf[26]='9';
332         }
333         }
334         }
335         }
336         }
337
338
339         // Get the GWorld
340         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
341         //assert(MAC_gWorld != NULL);
342
343         // Allocate memory for loading image
344         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
345         if (MAC_pixels == NULL) {
346         //UTIL_Error("Could not create Texture data.");
347         return;
348         }
349
350         // Get GWorld
351         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
352
353         // Make a picture Rectangle
354         MAC_picture_rectangle.left = 0;
355         MAC_picture_rectangle.right = screenwidth;
356         MAC_picture_rectangle.top = 0;
357         MAC_picture_rectangle.bottom = screenheight;
358
359         // Create new offscreen GWorld
360         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
361         if (MAC_error_code)     {
362         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
363         delete MAC_pixels;
364         //UTIL_Error("Could not create offscreen GWorld. ");
365         return;
366
367         }
368
369         // Copy OpenGL Context to new GWorld
370         glReadBuffer(GL_FRONT);
371         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
372
373         // Swizzle texture
374         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
375         unsigned char temp = MAC_pixels[byte+0];
376         MAC_pixels[byte+0] = MAC_pixels[byte+3];
377         MAC_pixels[byte+3] = MAC_pixels[byte+2];
378         MAC_pixels[byte+2] = MAC_pixels[byte+1];
379         MAC_pixels[byte+1] = temp;
380         }
381
382         // Flip the image  :(   This could probably be optimized
383         int vert;
384         int src_index;
385         int dst_index;
386         unsigned char temp;
387         for (int horz = 0; horz < screenwidth; ++horz)
388         for (vert = 0; vert < screenheight / 2; ++vert) {
389         src_index = (screenwidth * vert + horz) * 4;
390         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
391
392         temp=MAC_pixels[src_index+0];
393         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
394         MAC_pixels[dst_index+0]=temp;
395
396         temp=MAC_pixels[src_index+1];
397         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
398         MAC_pixels[dst_index+1]=temp;
399
400         temp=MAC_pixels[src_index+2];
401         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
402         MAC_pixels[dst_index+2]=temp;
403
404         temp=MAC_pixels[src_index+3];
405         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
406         MAC_pixels[dst_index+3]=temp;
407         }
408
409
410
411         // Export the Gworld
412         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
413         if (MAC_error_code) {
414         //UTIL_Warning("Unable to export screenshot.");
415         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
416         ::DisposeGWorld(MAC_offscreen_graphics_port);
417         delete MAC_pixels;
418         return;
419         }
420
421         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
422         if (MAC_error_code) {
423         ::CloseComponent(QT_exporter);
424         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
425         ::DisposeGWorld(MAC_offscreen_graphics_port);
426         delete MAC_pixels;
427         //UTIL_Warning("Unable to export screenshot.");
428         return;
429         }
430
431         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
432         if (MAC_error_code) {
433         ::CloseComponent(QT_exporter);
434         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
435         ::DisposeGWorld(MAC_offscreen_graphics_port);
436         delete MAC_pixels;
437         //UTIL_Warning("Unable to export screenshot.");
438         return;
439         }
440
441         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
442         if (MAC_error_code) {
443         ::CloseComponent(QT_exporter);
444         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
445         ::DisposeGWorld(MAC_offscreen_graphics_port);
446         delete MAC_pixels;
447         //UTIL_Warning("Unable to export screenshot.");
448         return;
449         }
450
451         ::CloseComponent(QT_exporter);
452         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
453         ::DisposeGWorld(MAC_offscreen_graphics_port);
454
455         delete MAC_pixels;*/
456 }
457
458
459
460 void    Game::SetUpLighting(){
461         if(environment==snowyenvironment){
462                 light.color[0]=.65;
463                 light.color[1]=.65;
464                 light.color[2]=.7;
465                 light.ambient[0]=.4;
466                 light.ambient[1]=.4;
467                 light.ambient[2]=.44;
468         }
469         if(environment==desertenvironment){
470                 light.color[0]=.95;
471                 light.color[1]=.95;
472                 light.color[2]=.95;
473                 light.ambient[0]=.4;
474                 light.ambient[1]=.35;
475                 light.ambient[2]=.3;
476         }
477
478         if(environment==grassyenvironment){
479                 light.color[0]=.95;
480                 light.color[1]=.95;
481                 light.color[2]=1;
482                 light.ambient[0]=.4;
483                 light.ambient[1]=.4;
484                 light.ambient[2]=.44;
485         }
486         if(!skyboxtexture){
487                 light.color[0]=1;
488                 light.color[1]=1;
489                 light.color[2]=1;
490                 light.ambient[0]=.4;
491                 light.ambient[1]=.4;
492                 light.ambient[2]=.4;
493         }
494         float average;
495         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
496         light.color[0]*=(skyboxlightr+average)/2;
497         light.color[1]*=(skyboxlightg+average)/2;
498         light.color[2]*=(skyboxlightb+average)/2;
499         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
500         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
501         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
502         /*
503         light.ambient[0]=0;
504         light.ambient[1]=0;
505         light.ambient[2]=0;     */
506 }
507
508 int Game::findPathDist(int start,int end){
509         int i,j,k,smallestcount,count,connected;
510         int last,last2,last3,last4;
511         int closest;
512
513         smallestcount=1000;
514         for(i=0;i<50;i++){
515                 count=0;
516                 last=start;
517                 last2=-1;
518                 last3=-1;
519                 last4=-1;
520                 while(last!=end&&count<30){
521                         closest=-1;
522                         for(j=0;j<numpathpoints;j++){
523                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
524                                 {
525                                         connected=0;
526                                         if(numpathpointconnect[j])
527                                                 for(k=0;k<numpathpointconnect[j];k++){
528                                                         if(pathpointconnect[j][k]==last)connected=1;
529                                                 }
530                                                 if(!connected)
531                                                         if(numpathpointconnect[last])
532                                                                 for(k=0;k<numpathpointconnect[last];k++){
533                                                                         if(pathpointconnect[last][k]==j)connected=1;
534                                                                 }
535                                                                 if(connected)
536                                                                         if(closest==-1||Random()%2==0){
537                                                                                 closest=j;
538                                                                         }
539                                 }
540                         }
541                         last4=last3;
542                         last3=last2;
543                         last2=last;
544                         last=closest;
545                         count++;
546                 }
547                 if(count<smallestcount)smallestcount=count;
548         }
549         return smallestcount;
550 }
551
552 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
553         static XYZ colpoint,colviewer,coltarget;
554         static float minx,minz,maxx,maxz,miny,maxy;
555         static int i;
556
557         //startpoint.y+=.7;
558         //endpoint.y+=.7;
559         //startpoint.y-=.1;
560         //endpoint.y-=.1;
561
562         minx=startpoint.x;
563         if(minx>endpoint.x)minx=endpoint.x;
564         miny=startpoint.y;
565         if(miny>endpoint.y)miny=endpoint.y;
566         minz=startpoint.z;
567         if(minz>endpoint.z)minz=endpoint.z;
568
569         maxx=startpoint.x;
570         if(maxx<endpoint.x)maxx=endpoint.x;
571         maxy=startpoint.y;
572         if(maxy<endpoint.y)maxy=endpoint.y;
573         maxz=startpoint.z;
574         if(maxz<endpoint.z)maxz=endpoint.z;
575
576         minx-=1;
577         miny-=1;
578         minz-=1;
579         maxx+=1;
580         maxy+=1;
581         maxz+=1;
582
583         for(i=0;i<objects.numobjects;i++){
584                 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){
585                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
586                                 colviewer=startpoint;
587                                 coltarget=endpoint;
588                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
589                         }
590                 }
591         }
592
593         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
594
595         return -1;
596 }
597
598 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
599         static XYZ colpoint,colviewer,coltarget;
600         static float minx,minz,maxx,maxz,miny,maxy;
601         static int i;
602
603         //startpoint.y+=.7;
604         //endpoint.y+=.7;
605         //startpoint.y-=.1;
606         //endpoint.y-=.1;
607
608         minx=startpoint.x;
609         if(minx>endpoint.x)minx=endpoint.x;
610         miny=startpoint.y;
611         if(miny>endpoint.y)miny=endpoint.y;
612         minz=startpoint.z;
613         if(minz>endpoint.z)minz=endpoint.z;
614
615         maxx=startpoint.x;
616         if(maxx<endpoint.x)maxx=endpoint.x;
617         maxy=startpoint.y;
618         if(maxy<endpoint.y)maxy=endpoint.y;
619         maxz=startpoint.z;
620         if(maxz<endpoint.z)maxz=endpoint.z;
621
622         minx-=1;
623         miny-=1;
624         minz-=1;
625         maxx+=1;
626         maxy+=1;
627         maxz+=1;
628
629         if(what!=1000){
630                 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){
631                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
632                                 colviewer=startpoint;
633                                 coltarget=endpoint;
634                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
635                         }
636                 }
637         }
638
639         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
640
641         return -1;
642 }
643
644 void    Game::Setenvironment(int which)
645 {
646         LOGFUNC;
647
648         LOG(" Setting environment...");
649
650         float temptexdetail;
651         environment=which;
652 /*
653         OPENAL_SetPaused(channels[music1snow], true);
654         OPENAL_SetPaused(channels[music1grass], true);
655         OPENAL_SetPaused(channels[music1desert], true);
656         OPENAL_SetPaused(channels[wind], true);
657         OPENAL_SetPaused(channels[desertambient], true);
658 */
659         OPENAL_SetPaused(channels[stream_music1snow], true);
660         OPENAL_SetPaused(channels[stream_music1grass], true);
661         OPENAL_SetPaused(channels[stream_music1desert], true);
662         OPENAL_SetPaused(channels[stream_wind], true);
663         OPENAL_SetPaused(channels[stream_desertambient], true);
664
665
666         if(environment==snowyenvironment){
667                 windvector=0;
668                 windvector.z=3;
669                 if(ambientsound){
670                         //PlaySoundEx( wind, samp[wind], NULL, true);
671                         PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
672                         OPENAL_SetPaused(channels[stream_wind], false);
673                         OPENAL_SetVolume(channels[stream_wind], 256);
674                 }
675
676                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
677                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
678                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
679                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
680
681                 OPENAL_Sample_Free(samp[footstepsound]);
682                 OPENAL_Sample_Free(samp[footstepsound2]);
683                 OPENAL_Sample_Free(samp[footstepsound3]);
684                 OPENAL_Sample_Free(samp[footstepsound4]);
685                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
686                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
687                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
688                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
689                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
690                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
691                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
692                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
693
694                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
695
696                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
697
698                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
699
700
701
702
703                 temptexdetail=texdetail;
704                 if(texdetail>1)texdetail=4;
705                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
706                         ":Data:Textures:Skybox(snow):Left.jpg",
707                         ":Data:Textures:Skybox(snow):Back.jpg",
708                         ":Data:Textures:Skybox(snow):Right.jpg",
709                         ":Data:Textures:Skybox(snow):Up.jpg",
710                         ":Data:Textures:Skybox(snow):Down.jpg",
711                         ":Data:Textures:Skybox(snow):Cloud.jpg",
712                         ":Data:Textures:Skybox(snow):Reflect.jpg");
713
714
715
716
717                 texdetail=temptexdetail;
718         }
719         if(environment==desertenvironment){
720                 windvector=0;
721                 windvector.z=2;
722                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
723                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
724                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
725                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
726
727
728                 if(ambientsound){
729                         //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
730                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
731                         OPENAL_SetPaused(channels[stream_desertambient], false);
732                         OPENAL_SetVolume(channels[stream_desertambient], 256);
733                 }
734
735                 OPENAL_Sample_Free(samp[footstepsound]);
736                 OPENAL_Sample_Free(samp[footstepsound2]);
737                 OPENAL_Sample_Free(samp[footstepsound3]);
738                 OPENAL_Sample_Free(samp[footstepsound4]);
739                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
740                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
741                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
742                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
743                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
744                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
745                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
746                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
747
748                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
749
750                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
751
752                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
753
754
755
756                 temptexdetail=texdetail;
757                 if(texdetail>1)texdetail=4;
758                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
759                         ":Data:Textures:Skybox(sand):Left.jpg",
760                         ":Data:Textures:Skybox(sand):Back.jpg",
761                         ":Data:Textures:Skybox(sand):Right.jpg",
762                         ":Data:Textures:Skybox(sand):Up.jpg",
763                         ":Data:Textures:Skybox(sand):Down.jpg",
764                         ":Data:Textures:Skybox(sand):Cloud.jpg",
765                         ":Data:Textures:Skybox(sand):Reflect.jpg");
766
767
768
769
770                 texdetail=temptexdetail;
771         }
772         if(environment==grassyenvironment){
773                 windvector=0;
774                 windvector.z=2;
775                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
776                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
777                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
778                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
779
780                 if(ambientsound){
781                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
782                         OPENAL_SetPaused(channels[stream_wind], false);
783                         OPENAL_SetVolume(channels[stream_wind], 100);
784                 }
785
786                 OPENAL_Sample_Free(samp[footstepsound]);
787                 OPENAL_Sample_Free(samp[footstepsound2]);
788                 OPENAL_Sample_Free(samp[footstepsound3]);
789                 OPENAL_Sample_Free(samp[footstepsound4]);
790                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass1.ogg"), OPENAL_HW3D, 0, 0);
791                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass2.ogg"), OPENAL_HW3D, 0, 0);
792                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
793                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
794                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
795                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
796                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
797                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
798
799                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
800
801                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
802
803                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
804
805
806
807                 temptexdetail=texdetail;
808                 if(texdetail>1)texdetail=4;
809                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
810                         ":Data:Textures:Skybox(grass):Left.jpg",
811                         ":Data:Textures:Skybox(grass):Back.jpg",
812                         ":Data:Textures:Skybox(grass):Right.jpg",
813                         ":Data:Textures:Skybox(grass):Up.jpg",
814                         ":Data:Textures:Skybox(grass):Down.jpg",
815                         ":Data:Textures:Skybox(grass):Cloud.jpg",
816                         ":Data:Textures:Skybox(grass):Reflect.jpg");
817
818
819
820                 texdetail=temptexdetail;
821         }
822         temptexdetail=texdetail;
823         texdetail=1;
824         terrain.load(":Data:Textures:heightmap.png");
825
826         texdetail=temptexdetail;
827 }
828
829
830 void    Game::Loadlevel(int which){
831         stealthloading=0;
832
833         if(which==0)Loadlevel((char *)":Data:Maps:map1");
834         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
835         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
836         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
837         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
838         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
839         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
840         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
841         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
842         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
843         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
844         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
845         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
846         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
847         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
848         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
849         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
850         else Loadlevel((char *)":Data:Maps:mapsave");
851
852         whichlevel=which;
853 }
854
855 /*char * Game::MD5_string (unsigned char *string){
856 char temp[50];
857 char temp2[100];
858
859 strcpy(temp2,(const char *)string);
860 strcat((char *)temp2,(const char *)"Lugaru");
861 sprintf (temp, "%d",strlen((char *)temp2));
862 strcat((char *)temp2,temp);
863
864 MD5 context;
865 unsigned int len = strlen ( (char *)temp2);
866
867 context.update   ((unsigned char *)temp2, len);
868 context.finalize ();
869
870 return context.hex_digest();
871 }*/
872
873
874
875 void    Game::Loadlevel(char *name){
876         int i,j,k,l,m;
877         static int oldlevel;
878         int templength;
879         float lamefloat;
880         int lameint;
881
882         float headprop,legprop,armprop,bodyprop;
883
884         LOGFUNC;
885
886         LOG(std::string("Loading level...") + name);
887
888         if(!gameon)visibleloading=1;
889
890         if(stealthloading)visibleloading=0;
891
892         if(!stillloading)loadtime=0;
893         gamestarted=1;
894
895         numenvsounds=0;
896         //visibleloading=1;
897         if(tutoriallevel!=-1)tutoriallevel=0;
898         else tutoriallevel=1;
899
900         if(tutoriallevel==1)tutorialstage=0;
901         if(tutorialstage==0){
902                 tutorialstagetime=0;
903                 tutorialmaxtime=1;
904         }
905         loadingstuff=1;
906         if(!firstload){
907                 oldlevel=50;
908         }
909         OPENAL_SetPaused(channels[whooshsound], true);
910         OPENAL_SetPaused(channels[stream_firesound], true);
911
912         // Change the map filename into something that is os specific
913         char *FixedFN = ConvertFileName(name);
914
915         int mapvers;
916         FILE                    *tfile;
917         tfile=fopen( FixedFN, "rb" );
918         if(tfile)
919         {
920                 OPENAL_SetPaused(channels[stream_firesound], true);
921
922
923                 scoreadded=0;
924                 windialogue=0;
925
926                 hostiletime=0;
927
928                 won=0;
929
930                 //campaign=0;
931                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
932
933                 numdialogues=0;
934
935                 for(i=0;i<20;i++)
936                 {
937                         dialoguegonethrough[i]=0;
938                 }
939
940                 indialogue=-1;
941                 cameramode=0;
942
943                 damagedealt=0;
944                 damagetaken=0;
945
946                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
947
948                 if(difficulty!=2)minimap=1;
949                 else minimap=0;
950
951                 numhotspots=0;
952                 currenthotspot=-1;
953                 bonustime=1;
954
955                 skyboxtexture=1;
956                 skyboxr=1;
957                 skyboxg=1;
958                 skyboxb=1;
959
960                 freeze=0;
961                 winfreeze=0;
962
963                 for(i=0;i<100;i++)
964                 {
965                         bonusnum[i]=0;
966                 }
967
968                 numfalls=0;
969                 numflipfail=0;
970                 numseen=0;
971                 numstaffattack=0;
972                 numswordattack=0;
973                 numknifeattack=0;
974                 numunarmedattack=0;
975                 numescaped=0;
976                 numflipped=0;
977                 numwallflipped=0;
978                 numthrowkill=0;
979                 numafterkill=0;
980                 numreversals=0;
981                 numattacks=0;
982                 maxalarmed=0;
983                 numresponded=0;
984
985                 bonustotal=startbonustotal;
986                 bonus=0;
987                 gameon=1;
988                 changedelay=0;
989                 if(console)
990                 {
991                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
992                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
993                         OPENAL_SetPaused(channels[consolesuccesssound], false);
994                         freeze=0;
995                         console=0;
996                 }
997
998                 if(!stealthloading)
999                 {
1000                         terrain.numdecals=0;
1001                         sprites.numsprites=0;
1002                         for(i=0;i<objects.numobjects;i++)
1003                         {
1004                                 objects.model[i].numdecals=0;
1005                         }
1006
1007                         j=objects.numobjects;
1008                         for(i=0;i<j;i++)
1009                         {
1010                                 objects.DeleteObject(0);
1011                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1012                         }
1013
1014                         for(i=0;i<subdivision;i++)
1015                         {
1016                                 for(j=0;j<subdivision;j++)
1017                                 {
1018                                         terrain.patchobjectnum[i][j]=0;
1019                                 }
1020                         }
1021                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1022                 }
1023
1024                 weapons.numweapons=0;
1025
1026                 funpackf(tfile, "Bi", &mapvers);
1027                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
1028                 else indemo=0;
1029                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1030                 else maptype=mapkilleveryone;
1031                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1032                 else hostile=1;
1033                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1034                 else
1035                 {
1036                         viewdistance=100;
1037                         fadestart=.6;
1038                 }
1039                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1040                 else
1041                 {
1042                         skyboxtexture=1;
1043                         skyboxr=1;
1044                         skyboxg=1;
1045                         skyboxb=1;
1046                 }
1047                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1048                 else
1049                 {
1050                         skyboxlightr=skyboxr;
1051                         skyboxlightg=skyboxg;
1052                         skyboxlightb=skyboxb;
1053                 }
1054                 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);
1055                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1056                 player[0].originalcoords=player[0].coords;
1057                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1058                 {
1059                         for(j=0;j<player[0].num_weapons;j++)
1060                         {
1061                                 player[0].weaponids[j]=weapons.numweapons;
1062                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1063                                 weapons.owner[weapons.numweapons]=0;
1064                                 weapons.numweapons++;
1065                         }
1066                 }
1067
1068                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1069
1070                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1071                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1072                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1073                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1074
1075                 funpackf(tfile, "Bi", &player[0].numclothes);
1076
1077                 if(mapvers>=9)
1078                 {
1079                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1080                 }
1081                 else
1082                 {
1083                         player[0].whichskin=0;
1084                         player[0].creature=rabbittype;
1085                 }
1086
1087                 for(i=0;i<max_dialogues;i++)
1088                 {
1089                         for(j=0;j<max_dialoguelength;j++)
1090                         {
1091                                 for(k=0;k<128;k++)
1092                                 {
1093                                         dialoguetext[i][j][k]='\0';
1094                                 }
1095                                 for(k=0;k<64;k++)
1096                                 {
1097                                         dialoguename[i][j][k]='\0';
1098                                 }
1099                         }
1100                 }
1101
1102                 player[0].lastattack=-1;
1103                 player[0].lastattack2=-1;
1104                 player[0].lastattack3=-1;
1105
1106                 if(mapvers>=8)
1107                 {
1108                         funpackf(tfile, "Bi", &numdialogues);
1109                         if(numdialogues)
1110                         {
1111                                 for(k=0;k<numdialogues;k++)
1112                                 {
1113                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1114                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1115                                         for(l=0;l<10;l++)
1116                                         {
1117                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1118                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1119                                         }
1120                                         if(numdialogueboxes)
1121                                         {
1122                                                 for(l=0;l<numdialogueboxes[k];l++)
1123                                                 {
1124                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1125                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1126                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1127                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1128                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1129
1130                                                         bool doneread;
1131
1132                                                         funpackf(tfile, "Bi",&templength);
1133                                                         if(templength>128||templength<=0)templength=128;
1134                                                         for(m=0;m<templength;m++){
1135                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1136                                                                 if(dialoguetext[k][l][m]=='\0')break;
1137                                                         }
1138
1139                                                         funpackf(tfile, "Bi",&templength);
1140                                                         if(templength>64||templength<=0)templength=64;
1141                                                         for(m=0;m<templength;m++){
1142                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1143                                                                 if(dialoguename[k][l][m]=='\0'){
1144                                                                         break;
1145                                                                 }
1146                                                         }
1147                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1148                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1149                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1150
1151                                                         for(m=0;m<10;m++)
1152                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1153
1154                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1155                                                 }
1156                                         }
1157                                 }
1158                         }
1159                 }
1160                 else numdialogues=0;
1161
1162                 if(player[0].numclothes)
1163                 {
1164                         for(k=0;k<player[0].numclothes;k++)
1165                         {
1166                                 funpackf(tfile, "Bi", &templength);
1167                                 for(l=0;l<templength;l++)
1168                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1169                                 player[0].clothes[k][templength]='\0';
1170                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1171                         }
1172                 }
1173
1174                 funpackf(tfile, "Bi", &environment);
1175
1176                 funpackf(tfile, "Bi", &objects.numobjects);
1177                 if(objects.numobjects)
1178                 {
1179                         for(i=0;i<objects.numobjects;i++)
1180                         {
1181                                 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]);
1182                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1183                         }
1184                 }
1185
1186                 if(mapvers>=7)
1187                 {
1188                         funpackf(tfile, "Bi", &numhotspots);
1189                         if(numhotspots)
1190                         {
1191                                 for(i=0;i<numhotspots;i++)
1192                                 {
1193                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1194                                         funpackf(tfile, "Bi", &templength);
1195                                         if(templength)
1196                                                 for(l=0;l<templength;l++)
1197                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1198                                         hotspottext[i][templength]='\0';
1199                                         if(hotspottype[i]==-111)indemo=1;
1200                                 }
1201                         }
1202                 }
1203                 else numhotspots=0;
1204
1205                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1206
1207                 if(!stealthloading)
1208                 {
1209                         objects.center=0;
1210                         for(i=0;i<objects.numobjects;i++)
1211                         {
1212                                 objects.center+=objects.position[i];
1213                         }
1214                         objects.center/=objects.numobjects;
1215
1216
1217                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1218
1219                         float maxdistance=0;
1220                         float tempdist;
1221                         int whichclosest;
1222                         for(i=0;i<objects.numobjects;i++)
1223                         {
1224                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1225                                 if(tempdist>maxdistance)
1226                                 {
1227                                         whichclosest=i;
1228                                         maxdistance=tempdist;
1229                                 }
1230                         }
1231                         objects.radius=fast_sqrt(maxdistance);
1232                 }
1233
1234                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1235                 //mapcenter=objects.center;
1236                 //mapradius=objects.radius;
1237
1238                 funpackf(tfile, "Bi", &numplayers);
1239                 int howmanyremoved=0;
1240                 bool removeanother=0;
1241                 if(numplayers>1&&numplayers<maxplayers)
1242                 {
1243                         for(i=1;i<numplayers;i++)
1244                         {
1245                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1246                                 removeanother=0;
1247
1248                                 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);
1249                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1250                                 else player[i-howmanyremoved].howactive=typeactive;
1251                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1252                                 else player[i-howmanyremoved].scale=-1;
1253                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1254                                 else player[i-howmanyremoved].immobile=0;
1255                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1256                                 else player[i-howmanyremoved].rotation=0;
1257                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1258                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1259                                         removeanother=1;
1260                                         howmanyremoved++;
1261                                 }
1262                                 if(!removeanother)
1263                                 {
1264                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1265                                         {
1266                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1267                                                 {
1268                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1269                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1270                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1271                                                         weapons.numweapons++;
1272                                                 }
1273                                         }
1274                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1275                                         //player[i-howmanyremoved].numwaypoints=10;
1276                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1277                                         {
1278                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1279                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1280                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1281                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1282                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1283                                         }
1284
1285                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1286                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1287
1288                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1289                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1290                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1291                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1292
1293                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1294                                         else
1295                                         {
1296                                                 headprop=1;
1297                                                 bodyprop=1;
1298                                                 armprop=1;
1299                                                 legprop=1;
1300                                         }
1301                                         if(player[i-howmanyremoved].creature==wolftype)
1302                                         {
1303                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1304                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1305                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1306                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1307                                         }
1308
1309                                         if(player[i-howmanyremoved].creature==rabbittype)
1310                                         {
1311                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1312                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1313                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1314                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1315                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1316                                         }
1317
1318                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1319                                         if(player[i-howmanyremoved].numclothes)
1320                                         {
1321                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1322                                                 {
1323                                                         int templength;
1324                                                         funpackf(tfile, "Bi", &templength);
1325                                                         for(l=0;l<templength;l++)
1326                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1327                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1328                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1329                                                 }
1330                                         }
1331                                 }
1332                         }
1333                 }
1334                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1335
1336                 numplayers-=howmanyremoved;
1337                 funpackf(tfile, "Bi", &numpathpoints);
1338                 if(numpathpoints>30||numpathpoints<0)
1339                         numpathpoints=0;
1340                 if(numpathpoints)
1341                 {
1342                         for(j=0;j<numpathpoints;j++)
1343                         {
1344                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1345                                 for(k=0;k<numpathpointconnect[j];k++){
1346                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1347                                 }
1348                         }
1349                 }
1350                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1351
1352                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1353
1354                 SetUpLighting();
1355                 if(environment!=oldenvironment)Setenvironment(environment);
1356                 oldenvironment=environment;
1357
1358                 if(!stealthloading)
1359                 {
1360                         j=objects.numobjects;
1361                         objects.numobjects=0;
1362                         for(i=0;i<j;i++)
1363                         {
1364                                 //if(objects.type[i]!=spiketype)
1365                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1366                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1367                         }
1368
1369                         //if(skyboxtexture){
1370                         terrain.DoShadows();
1371                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1372                         objects.DoShadows();
1373                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1374                         /*}
1375                         else terrain.DoLighting();
1376                         */
1377                 }
1378
1379                 fclose(tfile);
1380
1381                 oldlevel=whichlevel;
1382
1383
1384                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1385                 for(i=0;i<numplayers;i++)
1386                 {
1387                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1388                         player[i].burnt=0;
1389                         player[i].bled=0;
1390                         player[i].onfire=0;
1391                         if(i==0||player[i].scale<0)player[i].scale=.2;
1392                         player[i].skeleton.free=0;
1393                         player[i].skeleton.id=i;
1394                         //if(Random()%2==0)player[i].creature=wolftype;
1395                         //else player[i].creature=rabbittype;
1396                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1397                         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);
1398                         else
1399                         {
1400                                 if(player[i].creature!=wolftype){
1401                                         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);
1402                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1403                                 }
1404                                 if(player[i].creature==wolftype){
1405                                         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);
1406                                 }
1407                         }
1408
1409
1410                         int texsize;
1411                         texsize=512*512*3/texdetail/texdetail;
1412                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1413                         //player[i].skeleton.skinText.resize(texsize);
1414
1415                         LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1416
1417                         if(player[i].numclothes)
1418                         {
1419                                 for(j=0;j<player[i].numclothes;j++)
1420                                 {
1421                                         tintr=player[i].clothestintr[j];
1422                                         tintg=player[i].clothestintg[j];
1423                                         tintb=player[i].clothestintb[j];
1424                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1425                                 }
1426                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1427                         }
1428
1429                         player[i].currentanimation=bounceidleanim;
1430                         player[i].targetanimation=bounceidleanim;
1431                         player[i].currentframe=0;
1432                         player[i].targetframe=1;
1433                         player[i].target=0;
1434                         player[i].speed=1+(float)(Random()%100)/1000;
1435                         if(difficulty==0)player[i].speed-=.2;
1436                         if(difficulty==1)player[i].speed-=.1;
1437
1438                         player[i].velocity=0;
1439                         player[i].oldcoords=player[i].coords;
1440                         player[i].realoldcoords=player[i].coords;
1441
1442                         player[i].id=i;
1443                         player[i].skeleton.id=i;
1444                         player[i].updatedelay=0;
1445                         player[i].normalsupdatedelay=0;
1446
1447                         player[i].aitype=passivetype;
1448                         player[i].aitarget=0;
1449                         player[i].madskills=0;
1450
1451                         if(i==0)
1452                         {
1453                                 player[i].proportionhead=1.2;
1454                                 player[i].proportionbody=1.05;
1455                                 player[i].proportionarms=1.00;
1456                                 player[i].proportionlegs=1.1;
1457                                 player[i].proportionlegs.y=1.05;
1458                         }
1459                         player[i].headless=0;
1460                         player[i].currentoffset=0;
1461                         player[i].targetoffset=0;
1462                         /*player[i].armorhead=1;
1463                         player[i].armorhigh=1;
1464                         player[i].armorlow=1;
1465                         player[i].protectionhead=1;
1466                         player[i].protectionhigh=1;
1467                         player[i].protectionlow=1;
1468                         player[i].metalhead=1;
1469                         player[i].metalhigh=1;
1470                         player[i].metallow=1;
1471                         player[i].power=1;
1472                         player[i].speedmult=1;*/
1473
1474                         player[i].damagetolerance=200;
1475
1476                         if(player[i].creature==wolftype)
1477                         {
1478                                 /*player[i].proportionhead=1.1;
1479                                 player[i].proportionbody=1.1;
1480                                 player[i].proportionarms=1.1;
1481                                 player[i].proportionlegs=1.1;
1482                                 player[i].proportionlegs.y=1.1;*/
1483                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1484
1485                                 player[i].damagetolerance=300;
1486                         }
1487
1488                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1489                         if(cellophane)
1490                         {
1491                                 player[i].proportionhead.z=0;
1492                                 player[i].proportionbody.z=0;
1493                                 player[i].proportionarms.z=0;
1494                                 player[i].proportionlegs.z=0;
1495                         }
1496
1497                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1498
1499                         player[i].headmorphness=0;
1500                         player[i].targetheadmorphness=1;
1501                         player[i].headmorphstart=0;
1502                         player[i].headmorphend=0;
1503
1504                         player[i].pausetime=0;
1505
1506                         player[i].dead=0;
1507                         player[i].jumppower=5;
1508                         player[i].damage=0;
1509                         player[i].permanentdamage=0;
1510                         player[i].superpermanentdamage=0;
1511
1512                         player[i].forwardkeydown=0;
1513                         player[i].leftkeydown=0;
1514                         player[i].backkeydown=0;
1515                         player[i].rightkeydown=0;
1516                         player[i].jumpkeydown=0;
1517                         player[i].crouchkeydown=0;
1518                         player[i].throwkeydown=0;
1519
1520                         player[i].collided=-10;
1521                         player[i].loaded=1;
1522                         player[i].bloodloss=0;
1523                         player[i].weaponactive=-1;
1524                         player[i].weaponstuck=-1;
1525                         player[i].bleeding=0;
1526                         player[i].deathbleeding=0;
1527                         player[i].stunned=0;
1528                         player[i].hasvictim=0;
1529                         player[i].wentforweapon=0;
1530                 }
1531
1532                 player[0].aitype=playercontrolled;
1533                 player[0].weaponactive=-1;
1534
1535                 if(difficulty==1)
1536                 {
1537                         //player[0].speedmult=1/.9;
1538                         player[0].power=1/.9;
1539                 }
1540
1541                 if(difficulty==0)
1542                 {
1543                         //player[0].speedmult=1/.8;
1544                         player[0].power=1/.8;
1545                 }
1546
1547                 //player[0].weaponstuck=1;
1548
1549                 if(difficulty==1)player[0].damagetolerance=250;
1550                 if(difficulty==0)player[0].damagetolerance=300;
1551                 if(difficulty==0)player[0].armorhead*=1.5;
1552                 if(difficulty==0)player[0].armorhigh*=1.5;
1553                 if(difficulty==0)player[0].armorlow*=1.5;
1554                 cameraloc=player[0].coords;
1555                 cameraloc.y+=5;
1556                 rotation=player[0].rotation;
1557
1558                 hawkcoords=player[0].coords;
1559                 hawkcoords.y+=30;
1560
1561                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1562                 //weapons.numweapons=numplayers;
1563                 for(i=0;i<weapons.numweapons;i++)
1564                 {
1565                         weapons.bloody[i]=0;
1566                         weapons.blooddrip[i]=0;
1567                         weapons.blooddripdelay[i]=0;
1568                         weapons.onfire[i]=0;
1569                         weapons.flamedelay[i]=0;
1570                         weapons.damage[i]=0;
1571                         //weapons.type[i]=sword;
1572                         if(weapons.type[i]==sword){
1573                                 weapons.mass[i]=1.5;
1574                                 weapons.tipmass[i]=1;
1575                                 weapons.length[i]=.8;
1576                         }
1577                         if(weapons.type[i]==staff){
1578                                 weapons.mass[i]=2;
1579                                 weapons.tipmass[i]=1;
1580                                 weapons.length[i]=1.5;
1581                         }
1582                         if(weapons.type[i]==knife){
1583                                 weapons.mass[i]=1;
1584                                 weapons.tipmass[i]=1.2;
1585                                 weapons.length[i]=.25;
1586                         }
1587                         weapons.position[i]=-1000;
1588                         weapons.tippoint[i]=-1000;
1589                 }
1590
1591 /*              for(i=0;i<32;i++){
1592                         //if(i<16||i>20)
1593                         OPENAL_StopSound(i);
1594                 }
1595 */
1596                 LOG("Starting background music...");
1597
1598                 OPENAL_StopSound(OPENAL_ALL);
1599                 if(environment==snowyenvironment)
1600                 {
1601                         if(ambientsound)
1602                         {
1603                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1604                                 OPENAL_SetPaused(channels[stream_wind], false);
1605                                 OPENAL_SetVolume(channels[stream_wind], 256);
1606                         }
1607                 }
1608                 else if(environment==desertenvironment)
1609                 {
1610                         if(ambientsound)
1611                         {
1612                                 //PlaySoundEx(desertambient,
1613                                 //      samp[desertambient], NULL, true);
1614                                 PlayStreamEx(stream_desertambient,
1615                                         strm[stream_desertambient], NULL, true);
1616                                 OPENAL_SetPaused(channels[stream_desertambient], false);
1617                                 OPENAL_SetVolume(channels[stream_desertambient], 256);
1618                         }
1619                 }
1620                 else if(environment==grassyenvironment)
1621                 {
1622                         if(ambientsound)
1623                         {
1624                                 //PlaySoundEx(wind, samp[wind], NULL, true);
1625                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1626                                 OPENAL_SetPaused(channels[stream_wind], false);
1627                                 OPENAL_SetVolume(channels[stream_wind], 100);
1628                         }
1629                 }
1630                 oldmusicvolume[0]=0;
1631                 oldmusicvolume[1]=0;
1632                 oldmusicvolume[2]=0;
1633                 oldmusicvolume[3]=0;
1634
1635
1636                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1637                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1638                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1639                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1640                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1641                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1642                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1643                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1644                 */
1645
1646                 if(!firstload)
1647                 {
1648                         firstload=1;
1649                 }
1650         }
1651         leveltime=0;
1652         loadingstuff=0;
1653         visibleloading=0;
1654 }
1655
1656 void    Game::Tick()
1657 {
1658         static int i,k,j,l,m;
1659         static XYZ facing,flatfacing,absflatfacing;
1660         static XYZ rotatetarget;
1661         static bool oldkey;
1662         static float oldtargetrotation;
1663         static int target, numgood;
1664         static XYZ tempcoords1,tempcoords2;
1665         static XYZ test;
1666         static XYZ test2;
1667         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1668         static int whichhit;
1669         static bool donesomething;
1670         static bool oldjumpkeydown;
1671
1672         int templength;
1673
1674         float headprop,bodyprop,armprop,legprop;
1675
1676         for(i=0;i<15;i++){
1677                 displaytime[i]+=multiplier;
1678         }
1679
1680         static unsigned char    theKeyMap[16];
1681         GetKeys( theKeyMap );
1682
1683         keyboardfrozen=0;
1684
1685
1686         static bool mainmenutogglekeydown;
1687         if(!console){
1688                 if(mainmenu&&endgame==1)mainmenu=10;
1689                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1690                         for(j=0;j<255;j++){
1691                                 displaytext[0][j]=' ';
1692                         }
1693                         displaychars[0]=0;
1694                         displayselected=0;
1695                         entername=0;
1696                         mainmenutogglekeydown=1;
1697                 }
1698                 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==13||mainmenu==17||mainmenu==10)){
1699                         selected=-1;
1700                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1701                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1702                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1703                                 else if(mainmenu==0&&winfreeze){
1704                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1705                                         stealthloading=1;
1706                                         else stealthloading=0;
1707
1708                                         if(!stealthloading){
1709                                         float gLoc[3]={0,0,0};
1710                                         float vel[3]={0,0,0};
1711                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1712                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1713                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1714                                         OPENAL_SetVolume(channels[firestartsound], 256);
1715                                         OPENAL_SetPaused(channels[firestartsound], false);
1716                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1717
1718                                         flashr=1;
1719                                         flashg=0;
1720                                         flashb=0;
1721                                         flashamount=1;
1722                                         flashdelay=1;
1723                                         }
1724
1725                                         startbonustotal=0;
1726
1727                                         for(i=0;i<campaignnumlevels;i++){
1728                                         levelvisible[i]=0;
1729                                         levelhighlight[i]=0;
1730                                         }
1731
1732                                         levelorder[0]=0;
1733                                         levelvisible[0]=1;
1734                                         if(accountcampaignchoicesmade[accountactive])
1735                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1736                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1737                                         levelvisible[levelorder[i+1]]=1;
1738                                         }
1739                                         int whichlevelstart;
1740                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1741                                         if(whichlevelstart<0){
1742                                         campaignchoicenum=1;
1743                                         campaignchoicewhich[0]=0;
1744                                         }
1745                                         else
1746                                         {
1747                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1748                                         if(campaignchoicenum)
1749                                         for(i=0;i<campaignchoicenum;i++){
1750                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1751                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1752                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1753                                         }
1754                                         }
1755
1756                                         loading=2;
1757                                         loadtime=0;
1758                                         targetlevel=7;
1759                                         if(firstload)TickOnceAfter();
1760                                         if(!firstload)LoadStuff();
1761                                         //else {
1762                                         for(i=0;i<255;i++){
1763                                         mapname[i]='\0';
1764                                         }
1765                                         mapname[0]=':';
1766                                         mapname[1]='D';
1767                                         mapname[2]='a';
1768                                         mapname[3]='t';
1769                                         mapname[4]='a';
1770                                         mapname[5]=':';
1771                                         mapname[6]='M';
1772                                         mapname[7]='a';
1773                                         mapname[8]='p';
1774                                         mapname[9]='s';
1775                                         mapname[10]=':';
1776
1777                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1778                                         //accountcampaignchoicesmade[accountactive]++;
1779
1780
1781                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1782                                         whichchoice=0;
1783                                         visibleloading=1;
1784                                         stillloading=1;
1785                                         Loadlevel(mapname);
1786                                         campaign=1;
1787                                         mainmenu=0;
1788                                         gameon=1;
1789                                         OPENAL_SetPaused(channels[music3], true);
1790
1791                                         stealthloading=0;*/
1792                                 }
1793                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1794                                 if(mainmenu&&musictoggle){
1795                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1796                                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
1797                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
1798                                                 OPENAL_SetPaused(channels[stream_music3], false);
1799                                                 OPENAL_SetVolume(channels[stream_music3], 256);
1800                                                 OPENAL_SetPaused(channels[music1], true);
1801                                         }
1802                                 }
1803                                 if(!mainmenu){
1804                                         OPENAL_SetPaused(channels[stream_music3], true);
1805                                         OPENAL_SetPaused(channels[music1], false);
1806                                 }
1807                         }
1808                         if(mainmenu==3){
1809                                 float gLoc[3]={0,0,0};
1810                                 float vel[3]={0,0,0};
1811                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1812                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1813                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1814                                 OPENAL_SetVolume(channels[fireendsound], 256);
1815                                 OPENAL_SetPaused(channels[fireendsound], false);
1816                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1817
1818                                 flashr=1;
1819                                 flashg=0;
1820                                 flashb=0;
1821                                 flashamount=1;
1822                                 flashdelay=1;
1823
1824                                 if(newdetail>2)newdetail=detail;
1825                                 if(newdetail<0)newdetail=detail;
1826                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1827                                 if(newscreenheight<0)newscreenheight=screenheight;
1828
1829                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
1830                                 opstream << "Screenwidth:\n";
1831                                 opstream << newscreenwidth;
1832                                 opstream << "\nScreenheight:\n";
1833                                 opstream << newscreenheight;
1834                                 opstream << "\nMouse sensitivity:\n";
1835                                 opstream << usermousesensitivity;
1836                                 opstream << "\nBlur(0,1):\n";
1837                                 opstream << ismotionblur;
1838                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1839                                 opstream << newdetail;
1840                                 opstream << "\nFloating jump:\n";
1841                                 opstream << floatjump;
1842                                 opstream << "\nMouse jump:\n";
1843                                 opstream << mousejump;
1844                                 opstream << "\nAmbient sound:\n";
1845                                 opstream << ambientsound;
1846                                 opstream << "\nBlood (0,1,2):\n";
1847                                 opstream << bloodtoggle;
1848                                 opstream << "\nAuto slomo:\n";
1849                                 opstream << autoslomo;
1850                                 opstream << "\nFoliage:\n";
1851                                 opstream << foliage;
1852                                 opstream << "\nMusic:\n";
1853                                 opstream << musictoggle;
1854                                 opstream << "\nTrilinear:\n";
1855                                 opstream << trilinear;
1856                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1857                                 opstream << decals;
1858                                 opstream << "\nInvert mouse:\n";
1859                                 opstream << invertmouse;
1860                                 opstream << "\nGamespeed:\n";
1861                                 if(oldgamespeed==0)oldgamespeed=1;
1862                                 opstream << oldgamespeed;
1863                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1864                                 opstream << difficulty;
1865                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1866                                 opstream << damageeffects;
1867                                 opstream << "\nText:\n";
1868                                 opstream << texttoggle;
1869                                 opstream << "\nDebug:\n";
1870                                 opstream << debugmode;
1871                                 opstream << "\nVBL Sync:\n";
1872                                 opstream << vblsync;
1873                                 opstream << "\nShow Points:\n";
1874                                 opstream << showpoints;
1875                                 opstream << "\nAlways Blur:\n";
1876                                 opstream << alwaysblur;
1877                                 opstream << "\nImmediate mode (turn on on G5):\n";
1878                                 opstream << immediate;
1879                                 opstream << "\nVelocity blur:\n";
1880                                 opstream << velocityblur;
1881                             opstream << "\nVolume:\n";
1882                         opstream << volume;
1883                                 opstream << "\nForward key:\n";
1884                                 opstream << KeyToChar(forwardkey);
1885                                 opstream << "\nBack key:\n";
1886                                 opstream << KeyToChar(backkey);
1887                                 opstream << "\nLeft key:\n";
1888                                 opstream << KeyToChar(leftkey);
1889                                 opstream << "\nRight key:\n";
1890                                 opstream << KeyToChar(rightkey);
1891                                 opstream << "\nJump key:\n";
1892                                 opstream << KeyToChar(jumpkey);
1893                                 opstream << "\nCrouch key:\n";
1894                                 opstream << KeyToChar(crouchkey);
1895                                 opstream << "\nDraw key:\n";
1896                                 opstream << KeyToChar(drawkey);
1897                                 opstream << "\nThrow key:\n";
1898                                 opstream << KeyToChar(throwkey);
1899                                 opstream << "\nAttack key:\n";
1900                                 opstream << KeyToChar(attackkey);
1901                                 opstream << "\nChat key:\n";
1902                                 opstream << KeyToChar(chatkey);
1903                                 opstream << "\nDamage bar:\n";
1904                                 opstream << showdamagebar;
1905                                 opstream.close();
1906                         }
1907                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){
1908                                 float gLoc[3]={0,0,0};
1909                                 float vel[3]={0,0,0};
1910                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1911                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1912                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1913                                 OPENAL_SetVolume(channels[fireendsound], 256);
1914                                 OPENAL_SetPaused(channels[fireendsound], false);
1915                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1916
1917                                 flashr=1;
1918                                 flashg=0;
1919                                 flashb=0;
1920                                 flashamount=1;
1921                                 flashdelay=1;
1922                         }
1923                         if(mainmenu==3&&gameon)mainmenu=2;
1924                         if(mainmenu==3&&!gameon)mainmenu=1;
1925                         if(mainmenu==5&&gameon)mainmenu=2;
1926                         if(mainmenu==5&&!gameon)mainmenu=1;
1927                         if(mainmenu==4)mainmenu=3;
1928                         if(mainmenu==6)mainmenu=5;
1929                         if(mainmenu==7)mainmenu=1;
1930                         if(mainmenu==9)mainmenu=5;
1931                         if(mainmenu==11)mainmenu=5;
1932                         if(mainmenu==13)mainmenu=12;
1933                         if(mainmenu==10)mainmenu=5;
1934                         if(mainmenu==100){
1935                                 mainmenu=5;
1936                                 gameon=0;
1937                                 winfreeze=0;
1938                         }
1939                         mainmenutogglekeydown=1;
1940                 }
1941                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1942                         mainmenutogglekeydown=0;
1943                 }
1944         }
1945
1946         /*static bool minimaptogglekeydown;
1947         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1948         minimap=1-minimap;
1949         minimaptogglekeydown=1;
1950         }
1951         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1952         minimaptogglekeydown=0;
1953         }
1954         */
1955
1956         static bool minimaptogglekeydown;
1957         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
1958                 if(tutorialstage!=51)
1959                         tutorialstagetime=tutorialmaxtime;
1960                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
1961                 OPENAL_SetVolume(channels[consolefailsound], 128);
1962                 OPENAL_SetPaused(channels[consolefailsound], false);
1963                 minimaptogglekeydown=1;
1964         }
1965         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1966                 minimaptogglekeydown=0;
1967         }
1968
1969         if(mainmenu){
1970                 //menu buttons
1971                 if(mainmenu==1||mainmenu==2){
1972                         if(Button()&&!oldbutton&&selected==1){
1973                                 if(!gameon){
1974                                         float gLoc[3]={0,0,0};
1975                                         float vel[3]={0,0,0};
1976                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1977                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1978                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1979                                         OPENAL_SetVolume(channels[firestartsound], 256);
1980                                         OPENAL_SetPaused(channels[firestartsound], false);
1981                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1982
1983                                         flashr=1;
1984                                         flashg=0;
1985                                         flashb=0;
1986                                         flashamount=1;
1987                                         flashdelay=1;
1988
1989                                         //new game
1990                                         if(accountactive!=-1)mainmenu=5;
1991                                         else mainmenu=7;
1992                                         /*
1993                                         startbonustotal=0;
1994
1995                                         loading=2;
1996                                         loadtime=0;
1997                                         if(firstload)TickOnceAfter();
1998                                         if(!firstload)LoadStuff();
1999                                         else {
2000                                         Loadlevel(0);
2001                                         }
2002                                         mainmenu=0;
2003                                         gameon=1;
2004                                         OPENAL_SetPaused(channels[music3], true);       */
2005                                 }
2006                                 else
2007                                 {
2008                                         //resume
2009                                         mainmenu=0;
2010                                         OPENAL_SetPaused(channels[stream_music3], true);
2011                                         OPENAL_SetPaused(channels[music1], false);
2012                                 }
2013                         }
2014
2015                         if(Button()&&!oldbutton&&selected==2){
2016                                 float gLoc[3]={0,0,0};
2017                                 float vel[3]={0,0,0};
2018                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2019                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2020                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2021                                 OPENAL_SetVolume(channels[firestartsound], 256);
2022                                 OPENAL_SetPaused(channels[firestartsound], false);
2023                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2024
2025                                 flashr=1;
2026                                 flashg=0;
2027                                 flashb=0;
2028                                 flashamount=1;
2029                                 flashdelay=1;
2030
2031                                 //options
2032
2033                                 mainmenu=3;
2034
2035                                 if(newdetail>2)newdetail=detail;
2036                                 if(newdetail<0)newdetail=detail;
2037                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2038                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2039                                 if(newscreenheight>3000)newscreenheight=screenheight;
2040                                 if(newscreenheight<0)newscreenheight=screenheight;
2041                         }
2042
2043                         if(Button()&&!oldbutton&&selected==3){
2044                                 float gLoc[3]={0,0,0};
2045                                 float vel[3]={0,0,0};
2046                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2047                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2048                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2049                                 OPENAL_SetVolume(channels[fireendsound], 256);
2050                                 OPENAL_SetPaused(channels[fireendsound], false);
2051                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2052
2053                                 flashr=1;
2054                                 flashg=0;
2055                                 flashb=0;
2056                                 flashamount=1;
2057                                 flashdelay=1;
2058
2059                                 if(!gameon){
2060                                         //quit
2061                                         tryquit=1;
2062                                         OPENAL_SetPaused(channels[stream_music3], true);
2063                                 }
2064                                 else{
2065                                         //end game
2066                                         gameon=0;
2067                                         mainmenu=1;
2068                                 }
2069                         }
2070                         if(Button())oldbutton=1;
2071                         else oldbutton=0;
2072                 }
2073
2074                 if(mainmenu==3){
2075                         if(Button()&&!oldbutton&&selected!=-1){
2076                                 float gLoc[3]={0,0,0};
2077                                 float vel[3]={0,0,0};
2078                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2079                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2080                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2081                                 OPENAL_SetVolume(channels[firestartsound], 256);
2082                                 OPENAL_SetPaused(channels[firestartsound], false);
2083                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2084                         }
2085                         if(Button()&&!oldbutton&&selected==0){
2086                         
2087                                 extern SDL_Rect **resolutions;
2088                                 bool isCustomResolution = true;
2089                                 bool found = false;
2090                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2091                                 {
2092                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2093                                                 isCustomResolution = false;
2094
2095                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2096                                         {
2097                                                 i++;
2098                                                 if (resolutions[i] != NULL)
2099                                                 {
2100                                                         newscreenwidth = (int) resolutions[i]->w;
2101                                                         newscreenheight = (int) resolutions[i]->h;
2102                                                 }
2103                                                 else if (isCustomResolution)
2104                                                 {
2105                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2106                                                         {
2107                                                                 newscreenwidth = (int) resolutions[0]->w;
2108                                                                 newscreenheight = (int) resolutions[0]->h;
2109                                                         }
2110                                                         else
2111                                                         {
2112                                                                 newscreenwidth = screenwidth;
2113                                                                 newscreenheight = screenheight;
2114                                                         }
2115                                                 }
2116                                                 else
2117                                                 {
2118                                                         newscreenwidth = (int) resolutions[0]->w;
2119                                                         newscreenheight = (int) resolutions[0]->h;
2120                                                 }
2121                                                 found = true;
2122                                         }
2123                                 }
2124
2125                                 if (!found)
2126                                 {
2127                                         newscreenwidth = (int) resolutions[0]->w;
2128                                         newscreenheight = (int) resolutions[0]->h;
2129                                 }
2130
2131                                 
2132                         }
2133                         if(Button()&&!oldbutton&&selected==1){
2134                                 newdetail++;
2135                                 if(newdetail>2)newdetail=0;
2136                         }
2137                         if(Button()&&!oldbutton&&selected==2){
2138                                 bloodtoggle++;
2139                                 if(bloodtoggle>2)bloodtoggle=0;
2140                         }
2141                         if(Button()&&!oldbutton&&selected==3){
2142                                 difficulty++;
2143                                 if(difficulty>2)difficulty=0;
2144                         }
2145                         if(Button()&&!oldbutton&&selected==4){
2146                                 ismotionblur=1-ismotionblur;
2147                         }
2148                         if(Button()&&!oldbutton&&selected==5){
2149                                 decals=1-decals;
2150                         }
2151                         if(Button()&&!oldbutton&&selected==6){
2152                                 musictoggle=1-musictoggle;
2153
2154                                 if(!musictoggle){
2155                                         OPENAL_SetPaused(channels[music1], true);
2156                                         OPENAL_SetPaused(channels[stream_music2], true);
2157                                         OPENAL_SetPaused(channels[stream_music3], true);
2158
2159                                         for(i=0;i<4;i++){
2160                                                 oldmusicvolume[i]=0;
2161                                                 musicvolume[i]=0;
2162                                         }
2163                                 }
2164
2165                                 if(musictoggle){
2166                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2167                                         OPENAL_SetPaused(channels[stream_music3], false);
2168                                         OPENAL_SetVolume(channels[stream_music3], 256);
2169                                 }
2170                         }
2171                         if(Button()&&!oldbutton&&selected==9){
2172                                 invertmouse=1-invertmouse;
2173                         }
2174                         if(Button()&&!oldbutton&&selected==10){
2175                                 usermousesensitivity+=.2;
2176                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2177                         }
2178                         if(Button()&&!oldbutton&&selected==11){
2179                                 volume+=.1f;
2180                                 if(volume>1.0001f)volume=0;
2181                                 OPENAL_SetSFXMasterVolume((int)(volume*255));
2182                         }
2183                         if(Button()&&!oldbutton&&selected==7){
2184                                 /*float gLoc[3]={0,0,0};
2185                                 float vel[3]={0,0,0};
2186                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2187                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2188                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2189                                 OPENAL_SetVolume(channels[firestartsound], 256);
2190                                 OPENAL_SetPaused(channels[firestartsound], false);
2191                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2192                                 */
2193                                 flashr=1;
2194                                 flashg=0;
2195                                 flashb=0;
2196                                 flashamount=1;
2197                                 flashdelay=1;
2198
2199                                 //options
2200
2201                                 mainmenu=4;
2202                                 keyselect=-1;
2203                         }
2204                         if(Button()&&!oldbutton&&selected==8){
2205                                 float gLoc[3]={0,0,0};
2206                                 float vel[3]={0,0,0};
2207                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2208                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2209                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2210                                 OPENAL_SetVolume(channels[fireendsound], 256);
2211                                 OPENAL_SetPaused(channels[fireendsound], false);
2212                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2213
2214                                 flashr=1;
2215                                 flashg=0;
2216                                 flashb=0;
2217                                 flashamount=1;
2218                                 flashdelay=1;
2219
2220                                 if(newdetail>2)newdetail=detail;
2221                                 if(newdetail<0)newdetail=detail;
2222                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2223                                 if(newscreenheight<0)newscreenheight=screenheight;
2224
2225
2226                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2227                                 opstream << "Screenwidth:\n";
2228                                 opstream << newscreenwidth;
2229                                 opstream << "\nScreenheight:\n";
2230                                 opstream << newscreenheight;
2231                                 opstream << "\nMouse sensitivity:\n";
2232                                 opstream << usermousesensitivity;
2233                                 opstream << "\nBlur(0,1):\n";
2234                                 opstream << ismotionblur;
2235                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2236                                 opstream << newdetail;
2237                                 opstream << "\nFloating jump:\n";
2238                                 opstream << floatjump;
2239                                 opstream << "\nMouse jump:\n";
2240                                 opstream << mousejump;
2241                                 opstream << "\nAmbient sound:\n";
2242                                 opstream << ambientsound;
2243                                 opstream << "\nBlood (0,1,2):\n";
2244                                 opstream << bloodtoggle;
2245                                 opstream << "\nAuto slomo:\n";
2246                                 opstream << autoslomo;
2247                                 opstream << "\nFoliage:\n";
2248                                 opstream << foliage;
2249                                 opstream << "\nMusic:\n";
2250                                 opstream << musictoggle;
2251                                 opstream << "\nTrilinear:\n";
2252                                 opstream << trilinear;
2253                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2254                                 opstream << decals;
2255                                 opstream << "\nInvert mouse:\n";
2256                                 opstream << invertmouse;
2257                                 opstream << "\nGamespeed:\n";
2258                                 if(oldgamespeed==0)oldgamespeed=1;
2259                                 opstream << oldgamespeed;
2260                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2261                                 opstream << difficulty;
2262                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2263                                 opstream << damageeffects;
2264                                 opstream << "\nText:\n";
2265                                 opstream << texttoggle;
2266                                 opstream << "\nDebug:\n";
2267                                 opstream << debugmode;
2268                                 opstream << "\nVBL Sync:\n";
2269                                 opstream << vblsync;
2270                                 opstream << "\nShow Points:\n";
2271                                 opstream << showpoints;
2272                                 opstream << "\nAlways Blur:\n";
2273                                 opstream << alwaysblur;
2274                                 opstream << "\nImmediate mode (turn on on G5):\n";
2275                                 opstream << immediate;
2276                                 opstream << "\nVelocity blur:\n";
2277                                 opstream << velocityblur;
2278                             opstream << "\nVolume:\n";
2279                         opstream << volume;
2280                                 opstream << "\nForward key:\n";
2281                                 opstream << KeyToChar(forwardkey);
2282                                 opstream << "\nBack key:\n";
2283                                 opstream << KeyToChar(backkey);
2284                                 opstream << "\nLeft key:\n";
2285                                 opstream << KeyToChar(leftkey);
2286                                 opstream << "\nRight key:\n";
2287                                 opstream << KeyToChar(rightkey);
2288                                 opstream << "\nJump key:\n";
2289                                 opstream << KeyToChar(jumpkey);
2290                                 opstream << "\nCrouch key:\n";
2291                                 opstream << KeyToChar(crouchkey);
2292                                 opstream << "\nDraw key:\n";
2293                                 opstream << KeyToChar(drawkey);
2294                                 opstream << "\nThrow key:\n";
2295                                 opstream << KeyToChar(throwkey);
2296                                 opstream << "\nAttack key:\n";
2297                                 opstream << KeyToChar(attackkey);
2298                                 opstream << "\nChat key:\n";
2299                                 opstream << KeyToChar(chatkey);
2300                                 opstream << "\nDamage bar:\n";
2301                                 opstream << showdamagebar;
2302                                 opstream.close();
2303
2304                                 if(mainmenu==3&&gameon)mainmenu=2;
2305                                 if(mainmenu==3&&!gameon)mainmenu=1;
2306                         }
2307                         if(Button())oldbutton=1;
2308                         else oldbutton=0;
2309                 }
2310                 if(mainmenu==4){
2311                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2312                                 float gLoc[3]={0,0,0};
2313                                 float vel[3]={0,0,0};
2314                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2315                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2316                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2317                                 OPENAL_SetVolume(channels[firestartsound], 256);
2318                                 OPENAL_SetPaused(channels[firestartsound], false);
2319                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2320                         }
2321                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2322                                 keyselect=selected;
2323                                 oldbuttons[0]=1;
2324                                 oldbuttons[1]=1;
2325                                 oldbuttons[2]=1;
2326                         }
2327                         if(keyselect!=-1){
2328                                 for(i=0;i<3;i++)
2329                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2330                                 for(i=0;i<140;i++){
2331                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2332                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2333                                                         float gLoc[3]={0,0,0};
2334                                                         float vel[3]={0,0,0};
2335                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2336                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2337                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2338                                                         OPENAL_SetVolume(channels[fireendsound], 256);
2339                                                         OPENAL_SetPaused(channels[fireendsound], false);
2340                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2341
2342                                                         int keynum;
2343                                                         keynum=i;
2344                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2345                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2346
2347
2348
2349                                                         if(keyselect==0)forwardkey=keynum;
2350                                                         if(keyselect==1)backkey=keynum;
2351                                                         if(keyselect==2)leftkey=keynum;
2352                                                         if(keyselect==3)rightkey=keynum;
2353                                                         if(keyselect==4)crouchkey=keynum;
2354                                                         if(keyselect==5)jumpkey=keynum;
2355                                                         if(keyselect==6)drawkey=keynum;
2356                                                         if(keyselect==7)throwkey=keynum;
2357                                                         if(keyselect==8)attackkey=keynum;
2358                                                         keyselect=-1;
2359                                                 }
2360                                         }
2361                                 }}
2362                         if(Button()&&!oldbutton&&selected==9){
2363                                 float gLoc[3]={0,0,0};
2364                                 float vel[3]={0,0,0};
2365                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2366                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2367                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2368                                 OPENAL_SetVolume(channels[fireendsound], 256);
2369                                 OPENAL_SetPaused(channels[fireendsound], false);
2370                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2371
2372                                 flashr=1;
2373                                 flashg=0;
2374                                 flashb=0;
2375                                 flashamount=1;
2376                                 flashdelay=1;
2377
2378                                 mainmenu=3;
2379
2380                                 if(newdetail>2)newdetail=detail;
2381                                 if(newdetail<0)newdetail=detail;
2382                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2383                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2384                                 if(newscreenheight>3000)newscreenheight=screenheight;
2385                                 if(newscreenheight<0)newscreenheight=screenheight;
2386                         }
2387                 }
2388
2389                 if(mainmenu==5){
2390
2391                         if(endgame==2){
2392                                 accountcampaignchoicesmade[accountactive]=0;
2393                                 accountcampaignscore[accountactive]=0;
2394                                 accountcampaigntime[accountactive]=0;
2395                                 endgame=0;
2396                         }
2397
2398                         if(Button()&&!oldbutton&&selected==1){
2399                                 float gLoc[3]={0,0,0};
2400                                 float vel[3]={0,0,0};
2401                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2402                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2403                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2404                                 OPENAL_SetVolume(channels[firestartsound], 256);
2405                                 OPENAL_SetPaused(channels[firestartsound], false);
2406                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2407
2408                                 flashr=1;
2409                                 flashg=0;
2410                                 flashb=0;
2411                                 flashamount=1;
2412                                 flashdelay=1;
2413
2414                                 startbonustotal=0;
2415
2416                                 loading=2;
2417                                 loadtime=0;
2418                                 targetlevel=-1;
2419                                 if(firstload)TickOnceAfter();
2420                                 if(!firstload)LoadStuff();
2421                                 else {
2422                                         Loadlevel(-1);
2423                                 }
2424
2425                                 mainmenu=0;
2426                                 gameon=1;
2427                                 OPENAL_SetPaused(channels[stream_music3], true);
2428                         }
2429                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
2430                                 float gLoc[3]={0,0,0};
2431                                 float vel[3]={0,0,0};
2432                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2433                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2434                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2435                                 OPENAL_SetVolume(channels[firestartsound], 256);
2436                                 OPENAL_SetPaused(channels[firestartsound], false);
2437                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2438
2439                                 flashr=1;
2440                                 flashg=0;
2441                                 flashb=0;
2442                                 flashamount=1;
2443                                 flashdelay=1;
2444
2445                                 startbonustotal=0;
2446
2447                                 loading=2;
2448                                 loadtime=0;
2449                                 targetlevel=7;
2450                                 if(firstload)TickOnceAfter();
2451                                 if(!firstload)LoadStuff();
2452                                 //else {
2453                                 for(i=0;i<255;i++){
2454                                         mapname[i]='\0';
2455                                 }
2456                                 mapname[0]=':';
2457                                 mapname[1]='D';
2458                                 mapname[2]='a';
2459                                 mapname[3]='t';
2460                                 mapname[4]='a';
2461                                 mapname[5]=':';
2462                                 mapname[6]='M';
2463                                 mapname[7]='a';
2464                                 mapname[8]='p';
2465                                 mapname[9]='s';
2466                                 mapname[10]=':';
2467                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2468                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2469                                 visibleloading=1;
2470                                 stillloading=1;
2471                                 Loadlevel(mapname);
2472                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2473                                 //}
2474                                 campaign=1;
2475                                 mainmenu=0;
2476                                 gameon=1;
2477                                 OPENAL_SetPaused(channels[stream_music3], true);
2478                         }
2479                         if(Button()&&!oldbutton&&selected==4){
2480                                 float gLoc[3]={0,0,0};
2481                                 float vel[3]={0,0,0};
2482                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2483                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2484                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2485                                 OPENAL_SetVolume(channels[fireendsound], 256);
2486                                 OPENAL_SetPaused(channels[fireendsound], false);
2487                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2488
2489                                 flashr=1;
2490                                 flashg=0;
2491                                 flashb=0;
2492                                 flashamount=1;
2493                                 flashdelay=1;
2494
2495                                 if(mainmenu==5&&gameon)mainmenu=2;
2496                                 if(mainmenu==5&&!gameon)mainmenu=1;
2497                         }
2498                         if(Button()&&!oldbutton&&selected==5){
2499                                 float gLoc[3]={0,0,0};
2500                                 float vel[3]={0,0,0};
2501                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2502                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2503                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2504                                 OPENAL_SetVolume(channels[fireendsound], 256);
2505                                 OPENAL_SetPaused(channels[fireendsound], false);
2506                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2507
2508                                 flashr=1;
2509                                 flashg=0;
2510                                 flashb=0;
2511                                 flashamount=1;
2512                                 flashdelay=1;
2513
2514                                 mainmenu=7;
2515                         }
2516                         if(Button()&&!oldbutton&&selected==3){
2517                                 float gLoc[3]={0,0,0};
2518                                 float vel[3]={0,0,0};
2519                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2520                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2521                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2522                                 OPENAL_SetVolume(channels[firestartsound], 256);
2523                                 OPENAL_SetPaused(channels[firestartsound], false);
2524                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2525
2526                                 flashr=1;
2527                                 flashg=0;
2528                                 flashb=0;
2529                                 flashamount=1;
2530                                 flashdelay=1;
2531
2532                                 mainmenu=6;
2533                         }
2534                         if(Button()&&!oldbutton&&selected==2){
2535                                 float gLoc[3]={0,0,0};
2536                                 float vel[3]={0,0,0};
2537                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2538                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2539                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2540                                 OPENAL_SetVolume(channels[firestartsound], 256);
2541                                 OPENAL_SetPaused(channels[firestartsound], false);
2542                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2543
2544                                 flashr=1;
2545                                 flashg=0;
2546                                 flashb=0;
2547                                 flashamount=1;
2548                                 flashdelay=1;
2549
2550                                 mainmenu=9;
2551                         }
2552                         if(Button())oldbutton=1;
2553                         else oldbutton=0;
2554                 }
2555                 if(mainmenu==9){
2556                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2557                                 float gLoc[3]={0,0,0};
2558                                 float vel[3]={0,0,0};
2559                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2560                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2561                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2562                                 OPENAL_SetVolume(channels[firestartsound], 256);
2563                                 OPENAL_SetPaused(channels[firestartsound], false);
2564                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2565
2566                                 flashr=1;
2567                                 flashg=0;
2568                                 flashb=0;
2569                                 flashamount=1;
2570                                 flashdelay=1;
2571
2572                                 startbonustotal=0;
2573
2574                                 loading=2;
2575                                 loadtime=0;
2576                                 targetlevel=selected;
2577                                 if(firstload)TickOnceAfter();
2578                                 if(!firstload)LoadStuff();
2579                                 else {
2580                                         Loadlevel(selected);
2581                                 }
2582                                 campaign=0;
2583
2584                                 mainmenu=0;
2585                                 gameon=1;
2586                                 OPENAL_SetPaused(channels[stream_music3], true);
2587                         }
2588                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2589                                 float gLoc[3]={0,0,0};
2590                                 float vel[3]={0,0,0};
2591                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2592                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2593                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2594                                 OPENAL_SetVolume(channels[fireendsound], 256);
2595                                 OPENAL_SetPaused(channels[fireendsound], false);
2596                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2597
2598                                 flashr=1;
2599                                 flashg=0;
2600                                 flashb=0;
2601                                 flashamount=1;
2602                                 flashdelay=1;
2603
2604                                 mainmenu=5;
2605                         }
2606                         if(Button())oldbutton=1;
2607                         else oldbutton=0;
2608                 }
2609                 if(mainmenu==11){
2610                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2611                                 float gLoc[3]={0,0,0};
2612                                 float vel[3]={0,0,0};
2613                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2614                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2615                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2616                                 OPENAL_SetVolume(channels[firestartsound], 256);
2617                                 OPENAL_SetPaused(channels[firestartsound], false);
2618                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2619
2620                                 flashr=1;
2621                                 flashg=0;
2622                                 flashb=0;
2623                                 flashamount=1;
2624                                 flashdelay=1;
2625
2626                                 startbonustotal=0;
2627
2628                                 loading=2;
2629                                 loadtime=0;
2630                                 targetlevel=selected;
2631                                 if(firstload)TickOnceAfter();
2632                                 if(!firstload)LoadStuff();
2633                                 else {
2634                                         Loadlevel(selected);
2635                                 }
2636                                 campaign=0;
2637
2638                                 mainmenu=0;
2639                                 gameon=1;
2640                                 OPENAL_SetPaused(channels[stream_music3], true);
2641                         }
2642                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2643                                 float gLoc[3]={0,0,0};
2644                                 float vel[3]={0,0,0};
2645                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2646                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2647                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2648                                 OPENAL_SetVolume(channels[fireendsound], 256);
2649                                 OPENAL_SetPaused(channels[fireendsound], false);
2650                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2651
2652                                 flashr=1;
2653                                 flashg=0;
2654                                 flashb=0;
2655                                 flashamount=1;
2656                                 flashdelay=1;
2657
2658                                 mainmenu=5;
2659                         }
2660                         if(Button())oldbutton=1;
2661                         else oldbutton=0;
2662                 }
2663                 if(mainmenu==10){
2664                         endgame=2;
2665                         if(Button()&&!oldbutton&&selected==3){
2666                                 float gLoc[3]={0,0,0};
2667                                 float vel[3]={0,0,0};
2668                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2669                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2670                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2671                                 OPENAL_SetVolume(channels[fireendsound], 256);
2672                                 OPENAL_SetPaused(channels[fireendsound], false);
2673                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2674
2675                                 flashr=1;
2676                                 flashg=0;
2677                                 flashb=0;
2678                                 flashamount=1;
2679                                 flashdelay=1;
2680
2681                                 mainmenu=5;
2682                         }
2683                         if(Button())oldbutton=1;
2684                         else oldbutton=0;
2685                 }
2686
2687                 if(mainmenu==6){
2688                         if(Button()&&!oldbutton&&selected!=-1){
2689                                 float gLoc[3]={0,0,0};
2690                                 float vel[3]={0,0,0};
2691                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2692                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2693                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2694                                 OPENAL_SetVolume(channels[firestartsound], 256);
2695                                 OPENAL_SetPaused(channels[firestartsound], false);
2696                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2697                         }
2698                         if(Button()&&!oldbutton&&selected==1){
2699                                 float gLoc[3]={0,0,0};
2700                                 float vel[3]={0,0,0};
2701                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2702                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2703                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2704                                 OPENAL_SetVolume(channels[fireendsound], 256);
2705                                 OPENAL_SetPaused(channels[fireendsound], false);
2706                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2707
2708                                 flashr=1;
2709                                 flashg=0;
2710                                 flashb=0;
2711                                 flashamount=1;
2712                                 flashdelay=1;
2713
2714                                 for(i=accountactive;i<numaccounts-1;i++){
2715                                         accountdifficulty[i]=accountdifficulty[i+1];
2716                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2717                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2718                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2719                                         }
2720                                         accountpoints[i]=accountpoints[i+1];
2721                                         for(j=0;j<50;j++){
2722                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2723                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2724                                         }
2725                                         for(j=0;j<60;j++){
2726                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2727                                         }
2728                                         for(j=0;j<256;j++){
2729                                                 accountname[i][j]=accountname[i+1][j];
2730                                         }
2731                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2732                                         accountprogress[i]=accountprogress[i+1];
2733                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2734                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2735                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2736                                 }
2737
2738                                 numaccounts--;
2739                                 accountactive=-1;
2740
2741
2742                                 mainmenu=7;
2743                         }
2744                         if(Button()&&!oldbutton&&selected==2){
2745                                 float gLoc[3]={0,0,0};
2746                                 float vel[3]={0,0,0};
2747                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2748                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2749                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2750                                 OPENAL_SetVolume(channels[fireendsound], 256);
2751                                 OPENAL_SetPaused(channels[fireendsound], false);
2752                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2753
2754                                 flashr=1;
2755                                 flashg=0;
2756                                 flashb=0;
2757                                 flashamount=1;
2758                                 flashdelay=1;
2759
2760                                 mainmenu=5;
2761                         }
2762                         if(Button())oldbutton=1;
2763                         else oldbutton=0;
2764                 }
2765                 if(mainmenu==7){
2766                         if(Button()&&!oldbutton&&selected!=-1){
2767                                 float gLoc[3]={0,0,0};
2768                                 float vel[3]={0,0,0};
2769                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2770                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2771                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2772                                 OPENAL_SetVolume(channels[firestartsound], 256);
2773                                 OPENAL_SetPaused(channels[firestartsound], false);
2774                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2775                         }
2776                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2777                                 entername=1;
2778                         }
2779                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2780                                 accountactive=selected-1;
2781                                 mainmenu=5;
2782                                 flashr=1;
2783                                 flashg=0;
2784                                 flashb=0;
2785                                 flashamount=1;
2786                                 flashdelay=1;
2787                         }
2788                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2789                                 float gLoc[3]={0,0,0};
2790                                 float vel[3]={0,0,0};
2791                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2792                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2793                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2794                                 OPENAL_SetVolume(channels[fireendsound], 256);
2795                                 OPENAL_SetPaused(channels[fireendsound], false);
2796                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2797
2798                                 flashr=1;
2799                                 flashg=0;
2800                                 flashb=0;
2801                                 flashamount=1;
2802                                 flashdelay=1;
2803
2804                                 mainmenu=1;
2805
2806                                 for(j=0;j<255;j++){
2807                                         displaytext[0][j]=' ';
2808                                 }
2809                                 displaychars[0]=0;
2810                                 displayselected=0;
2811                                 entername=0;
2812                         }
2813                         if(Button())oldbutton=1;
2814                         else oldbutton=0;
2815                 }
2816                 if(mainmenu==8){
2817                         if(Button()&&!oldbutton&&selected!=-1){
2818                                 float gLoc[3]={0,0,0};
2819                                 float vel[3]={0,0,0};
2820                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2821                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2822                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2823                                 OPENAL_SetVolume(channels[firestartsound], 256);
2824                                 OPENAL_SetPaused(channels[firestartsound], false);
2825                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2826
2827                                 if(selected==0)accountdifficulty[accountactive]=0;
2828                                 if(selected==1)accountdifficulty[accountactive]=1;
2829                                 if(selected==2)accountdifficulty[accountactive]=2;
2830
2831                                 mainmenu=5;
2832
2833                                 flashr=1;
2834                                 flashg=0;
2835                                 flashb=0;
2836                                 flashamount=1;
2837                                 flashdelay=1;
2838
2839                         }
2840                         if(Button())oldbutton=1;
2841                         else oldbutton=0;
2842                 }
2843
2844
2845                 if(Button())oldbutton=1;
2846                 else oldbutton=0;
2847
2848                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
2849                         tryquit=1;
2850                         if(mainmenu==3){
2851                                 if(newdetail>2)newdetail=detail;
2852                                 if(newdetail<0)newdetail=detail;
2853                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2854                                 if(newscreenheight<0)newscreenheight=screenheight;
2855
2856                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2857                                 opstream << "Screenwidth:\n";
2858                                 opstream << newscreenwidth;
2859                                 opstream << "\nScreenheight:\n";
2860                                 opstream << newscreenheight;
2861                                 opstream << "\nMouse sensitivity:\n";
2862                                 opstream << usermousesensitivity;
2863                                 opstream << "\nBlur(0,1):\n";
2864                                 opstream << ismotionblur;
2865                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2866                                 opstream << newdetail;
2867                                 opstream << "\nFloating jump:\n";
2868                                 opstream << floatjump;
2869                                 opstream << "\nMouse jump:\n";
2870                                 opstream << mousejump;
2871                                 opstream << "\nAmbient sound:\n";
2872                                 opstream << ambientsound;
2873                                 opstream << "\nBlood (0,1,2):\n";
2874                                 opstream << bloodtoggle;
2875                                 opstream << "\nAuto slomo:\n";
2876                                 opstream << autoslomo;
2877                                 opstream << "\nFoliage:\n";
2878                                 opstream << foliage;
2879                                 opstream << "\nMusic:\n";
2880                                 opstream << musictoggle;
2881                                 opstream << "\nTrilinear:\n";
2882                                 opstream << trilinear;
2883                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2884                                 opstream << decals;
2885                                 opstream << "\nInvert mouse:\n";
2886                                 opstream << invertmouse;
2887                                 opstream << "\nGamespeed:\n";
2888                                 if(oldgamespeed==0)oldgamespeed=1;
2889                                 opstream << oldgamespeed;
2890                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2891                                 opstream << difficulty;
2892                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2893                                 opstream << damageeffects;
2894                                 opstream << "\nText:\n";
2895                                 opstream << texttoggle;
2896                                 opstream << "\nDebug:\n";
2897                                 opstream << debugmode;
2898                                 opstream << "\nVBL Sync:\n";
2899                                 opstream << vblsync;
2900                                 opstream << "\nShow Points:\n";
2901                                 opstream << showpoints;
2902                                 opstream << "\nAlways Blur:\n";
2903                                 opstream << alwaysblur;
2904                                 opstream << "\nImmediate mode (turn on on G5):\n";
2905                                 opstream << immediate;
2906                                 opstream << "\nVelocity blur:\n";
2907                                 opstream << velocityblur;
2908                             opstream << "\nVolume:\n";
2909                         opstream << volume;
2910                                 opstream << "\nForward key:\n";
2911                                 opstream << KeyToChar(forwardkey);
2912                                 opstream << "\nBack key:\n";
2913                                 opstream << KeyToChar(backkey);
2914                                 opstream << "\nLeft key:\n";
2915                                 opstream << KeyToChar(leftkey);
2916                                 opstream << "\nRight key:\n";
2917                                 opstream << KeyToChar(rightkey);
2918                                 opstream << "\nJump key:\n";
2919                                 opstream << KeyToChar(jumpkey);
2920                                 opstream << "\nCrouch key:\n";
2921                                 opstream << KeyToChar(crouchkey);
2922                                 opstream << "\nDraw key:\n";
2923                                 opstream << KeyToChar(drawkey);
2924                                 opstream << "\nThrow key:\n";
2925                                 opstream << KeyToChar(throwkey);
2926                                 opstream << "\nAttack key:\n";
2927                                 opstream << KeyToChar(attackkey);
2928                                 opstream << "\nChat key:\n";
2929                                 opstream << KeyToChar(chatkey);
2930                                 opstream << "\nDamage bar:\n";
2931                                 opstream << showdamagebar;
2932                                 opstream.close();
2933                         }
2934                 }
2935
2936                 if(mainmenu==1||mainmenu==2){
2937                         if(loaddistrib>4)transition+=multiplier/8;
2938                         if(transition>1){
2939                                 transition=0;
2940                                 anim++;
2941                                 if(anim>4)anim=0;
2942                                 loaddistrib=0;
2943                         }
2944                 }
2945                 OPENAL_SetFrequency(channels[stream_music3], 22050);
2946
2947                 if(entername){
2948                         for(i=0;i<140;i++){
2949                                 if(IsKeyDown(theKeyMap, i)){
2950                                         togglekeydelay[i]+=multiplier;
2951                                         if(togglekeydelay[i]>.4){
2952                                                 togglekey[i]=0;
2953                                                 togglekeydelay[i]=.36;
2954                                         }
2955                                         if(!togglekey[i]){
2956                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
2957                                                         for(j=255;j>=displayselected+1;j--){
2958                                                                 displaytext[0][j]=displaytext[0][j-1];
2959                                                         }
2960                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
2961                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
2962                                                         displayselected++;
2963                                                         displaychars[0]++;
2964                                                 }
2965                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
2966                                                         for(j=displayselected-1;j<255;j++){
2967                                                                 displaytext[0][j]=displaytext[0][j+1];
2968                                                         }
2969                                                         displaytext[0][255]=' ';
2970                                                         displayselected--;
2971                                                         displaychars[0]--;
2972                                                 }
2973                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
2974                                                         displayselected--;
2975                                                 }
2976                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
2977                                                         displayselected++;
2978                                                 }
2979                                                 if(i==MAC_RETURN_KEY&&entername){
2980                                                         if(displaychars[0]){
2981                                                                 numaccounts++;
2982                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
2983                                                                 accountactive=numaccounts-1;
2984                                                                 accountdifficulty[accountactive]=1;
2985                                                                 accountprogress[accountactive]=0;
2986                                                                 accountpoints[accountactive]=0;
2987                                                                 accountcampaigntime[accountactive]=0;
2988                                                                 accountcampaignscore[accountactive]=0;
2989                                                                 accountcampaignfasttime[accountactive]=0;
2990                                                                 accountcampaignhighscore[accountactive]=0;
2991                                                                 for(j=0;j<50;j++){
2992                                                                         accounthighscore[accountactive][j]=0;
2993                                                                         accountfasttime[accountactive][j]=0;
2994                                                                 }
2995                                                                 for(j=0;j<60;j++){
2996                                                                         accountunlocked[accountactive][j]=0;
2997                                                                 }
2998                                                                 accountcampaignchoicesmade[accountactive]=0;
2999
3000                                                                 for(j=0;j<255;j++){
3001                                                                         displaytext[0][j]=' ';
3002                                                                 }
3003                                                                 displaychars[0]=0;
3004                                                                 displayselected=0;
3005                                                                 entername=0;
3006
3007                                                                 mainmenu=8;
3008
3009                                                                 flashr=1;
3010                                                                 flashg=0;
3011                                                                 flashb=0;
3012                                                                 flashamount=1;
3013                                                                 flashdelay=1;
3014
3015                                                                 float gLoc[3]={0,0,0};
3016                                                                 float vel[3]={0,0,0};
3017                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3018                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3019                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3020                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3021                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3022                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3023
3024                                                                 for(j=0;j<255;j++){
3025                                                                         displaytext[0][j]=' ';
3026                                                                 }
3027                                                                 displaychars[0]=0;
3028
3029
3030                                                                 displayselected=0;
3031                                                         }}
3032
3033                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3034                                                         if(displaychars[0]){
3035                                                                 sprintf (registrationname, "%s", displaytext[0]);
3036                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3037
3038                                                                 mainmenu=5;
3039                         
3040                                                                 flashr=1;
3041                                                                 flashg=0;
3042                                                                 flashb=0;
3043                                                                 flashamount=1;
3044                                                                 flashdelay=1;
3045
3046                                                                 float gLoc[3]={0,0,0};
3047                                                                 float vel[3]={0,0,0};
3048                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3049                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3050                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3051                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3052                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3053                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3054
3055                                                                 for(j=0;j<255;j++){
3056                                                                         displaytext[0][j]=' ';
3057                                                                 }
3058                                                                 displaychars[0]=0;
3059                         
3060                                                                 displayselected=0;
3061                                                         }}
3062                                         }
3063                                         togglekey[i]=1;
3064                                 }
3065                                 else {
3066                                         togglekey[i]=0;
3067                                         togglekeydelay[i]=0;
3068                                 }
3069                         }
3070
3071                         displayblinkdelay-=multiplier;
3072                         if(displayblinkdelay<=0){
3073                                 displayblinkdelay=.3;
3074                                 displayblink=1-displayblink;
3075                         }
3076                 }
3077         }
3078
3079         if(!mainmenu){
3080                 if(hostile==1)hostiletime+=multiplier;
3081                 else hostiletime=0;
3082                 if(!winfreeze)leveltime+=multiplier;
3083                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3084                         chatting=0;
3085                         console=0;
3086                         freeze=0;
3087                         displaychars[0]=0;
3088                 }
3089
3090                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3091                         chatting=1;
3092                         chattogglekeydown=1;
3093                         togglekey[chatkey]=1;
3094                         togglekeydelay[chatkey]=-20;
3095                 }
3096
3097                 if(!IsKeyDown(theKeyMap, chatkey)){
3098                         chattogglekeydown=0;
3099                 }
3100
3101                 if(chatting){
3102                         for(i=0;i<140;i++){
3103                                 if(IsKeyDown(theKeyMap, i)){
3104                                         togglekeydelay[i]+=multiplier;
3105                                         if(togglekeydelay[i]>.4){
3106                                                 togglekey[i]=0;
3107                                                 togglekeydelay[i]=.36;
3108                                         }
3109                                         if(!togglekey[i]){
3110                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3111                                                         for(j=255;j>=displayselected+1;j--){
3112                                                                 displaytext[0][j]=displaytext[0][j-1];
3113                                                         }
3114                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3115                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3116                                                         displayselected++;
3117                                                         displaychars[0]++;
3118                                                 }
3119                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3120                                                         for(j=displayselected-1;j<255;j++){
3121                                                                 displaytext[0][j]=displaytext[0][j+1];
3122                                                         }
3123                                                         displaytext[0][255]=' ';
3124                                                         displayselected--;
3125                                                         displaychars[0]--;
3126                                                 }
3127                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3128                                                         displayselected--;
3129                                                 }
3130                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3131                                                         displayselected++;
3132                                                 }
3133                                                 if(i==MAC_RETURN_KEY){
3134                                                         if(displaychars[0]){
3135                                                                 /*for(j=0;j<displaychars[0];j++){
3136                                                                 talkname[j]=displaytext[0][j];
3137                                                                 }
3138                                                                 talkname[displaychars[0]]='\0';
3139                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3140                                                                 //NetworkSendInformation(chatname);
3141                                                                 */
3142                                                                 for(j=0;j<255;j++){
3143                                                                         displaytext[0][j]=' ';
3144                                                                 }
3145                                                                 displaychars[0]=0;
3146                                                                 displayselected=0;
3147                                                                 chatting=0;
3148                                                         }
3149                                                 }
3150                                         }
3151                                         togglekey[i]=1;
3152                                 }
3153                                 else {
3154                                         togglekey[i]=0;
3155                                         togglekeydelay[i]=0;
3156                                 }
3157                         }
3158
3159                         displayblinkdelay-=multiplier;
3160                         if(displayblinkdelay<=0){
3161                                 displayblinkdelay=.3;
3162                                 displayblink=1-displayblink;
3163                         }
3164                 }
3165
3166                 if(chatting)keyboardfrozen=1;
3167
3168                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3169                         freeze=1-freeze;
3170                         if(freeze){
3171                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3172                         }
3173                         freezetogglekeydown=1;
3174                 }
3175
3176                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3177                         freezetogglekeydown=0;
3178                 }
3179
3180                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3181                         console=1-console;
3182                         if(!console)freeze=0;
3183                         if(console){
3184                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3185                         }
3186                         consoletogglekeydown=1;
3187                 }
3188
3189                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3190                         consoletogglekeydown=0;
3191                 }
3192
3193                 if(console)freeze=1;
3194
3195                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3196                         for(i=0;i<140;i++){
3197                                 if(IsKeyDown(theKeyMap, i)){
3198                                         togglekeydelay[i]+=multiplier;
3199                                         if(togglekeydelay[i]>.4){
3200                                                 togglekey[i]=0;
3201                                                 togglekeydelay[i]=.36;
3202                                         }
3203                                         if(!togglekey[i]){
3204                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3205                                                         for(j=255;j>=consoleselected+1;j--){
3206                                                                 consoletext[0][j]=consoletext[0][j-1];
3207                                                         }
3208                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3209                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3210                                                         consoleselected++;
3211                                                         consolechars[0]++;
3212                                                 }
3213                                                 else if(i==MAC_ENTER_KEY){
3214                                                         for(j=255;j>=consoleselected+1;j--){
3215                                                                 consoletext[0][j]=consoletext[0][j-1];
3216                                                         }
3217                                                         consoletext[0][consoleselected]='\n';
3218                                                         consoleselected++;
3219                                                         consolechars[0]++;
3220                                                 }
3221                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3222                                                         for(j=consoleselected-1;j<255;j++){
3223                                                                 consoletext[0][j]=consoletext[0][j+1];
3224                                                         }
3225                                                         consoletext[0][255]=' ';
3226                                                         consoleselected--;
3227                                                         consolechars[0]--;
3228                                                 }
3229                                                 if(i==MAC_ARROW_UP_KEY){
3230                                                         if(archiveselected<14)archiveselected++;
3231                                                         for(j=0;j<255;j++){
3232                                                                 consolechars[0]=consolechars[archiveselected];
3233                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3234                                                                 consoleselected=consolechars[0];
3235                                                         }
3236                                                 }
3237                                                 if(i==MAC_ARROW_DOWN_KEY){
3238                                                         if(archiveselected>0)archiveselected--;
3239                                                         for(j=0;j<255;j++){
3240                                                                 consolechars[0]=consolechars[archiveselected];
3241                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3242                                                                 consoleselected=consolechars[0];
3243                                                         }
3244                                                 }
3245                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3246                                                         consoleselected--;
3247                                                 }
3248                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3249                                                         consoleselected++;
3250                                                 }
3251                                                 if(i==MAC_RETURN_KEY){
3252                                                         archiveselected=0;
3253                                                         donesomething=0;
3254                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3255                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3256                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3257                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3258                                                                 donesomething=1;
3259                                                                 tryquit=1;
3260                                                         }
3261                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3262                                                         for(j=5;j<consolechars[0];j++){
3263                                                         talkname[j-5]=consoletext[0][j];
3264                                                         }
3265                                                         talkname[consolechars[0]-5]='\0';
3266                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3267                                                         //NetworkSendInformation(chatname);
3268                                                         donesomething=1;
3269                                                         }
3270                                                         if(Compare(consoletext[0],"name ",0,4)){
3271                                                         int numchars;
3272                                                         numchars=consolechars[0]-5;
3273                                                         if(numchars>32)numchars=32;
3274                                                         for(j=5;j<numchars+5;j++){
3275                                                         talkname[j-5]=consoletext[0][j];
3276                                                         }
3277                                                         talkname[numchars]='\0';
3278                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3279                                                         //NetworkSendInformation(chatname);
3280                                                         sprintf (playerName, "%s",talkname);
3281                                                         //NetworkSendName(playerName);
3282                                                         donesomething=1;
3283                                                         }*/
3284                                                         if(Compare(consoletext[0],"map ",0,3)){
3285                                                                 mapname[0]=':';
3286                                                                 mapname[1]='D';
3287                                                                 mapname[2]='a';
3288                                                                 mapname[3]='t';
3289                                                                 mapname[4]='a';
3290                                                                 mapname[5]=':';
3291                                                                 mapname[6]='M';
3292                                                                 mapname[7]='a';
3293                                                                 mapname[8]='p';
3294                                                                 mapname[9]='s';
3295                                                                 mapname[10]=':';
3296                                                                 for(j=4;j<consolechars[0];j++){
3297                                                                         mapname[j-4+11]=consoletext[0][j];
3298                                                                 }
3299                                                                 mapname[consolechars[0]-4+11]='\0';
3300                                                                 Loadlevel(mapname);
3301                                                                 whichlevel=-2;
3302                                                                 campaign=0;
3303                                                                 donesomething=1;
3304                                                         }
3305                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3306                                                         int v;
3307                                                         unsigned char playerNameStr[32];
3308                                                         char theIPAddress[256];
3309                                                         char thePort[32];
3310                                                         NMUInt32 port = 25710;
3311
3312                                                         strcpy(playerName, "Client");
3313                                                         GameC2PStr( playerName, playerNameStr );
3314
3315                                                         for(j=0;j<consolechars[0]-8;j++){
3316                                                         theIPAddress[j]=consoletext[0][j+8];
3317                                                         }
3318                                                         theIPAddress[consolechars[0]-8]='\0';
3319
3320                                                         sprintf( thePort, "%li", port );
3321                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3322                                                         if(v)
3323                                                         {
3324                                                         if(consolechars[0]>0){
3325                                                         for(k=14;k>=1;k--){
3326                                                         for(j=0;j<255;j++){
3327                                                         consoletext[k][j]=consoletext[k-1][j];
3328                                                         }
3329                                                         consolechars[k]=consolechars[k-1];
3330                                                         }
3331                                                         for(j=0;j<255;j++){
3332                                                         consoletext[0][j]=' ';
3333                                                         }
3334                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3335                                                         else sprintf (consoletext[0], "Could not open connection");
3336
3337                                                         consolechars[0]=255;
3338                                                         consoleselected=0;
3339                                                         }
3340                                                         }
3341                                                         else
3342                                                         {
3343                                                         donesomething=1;
3344                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3345                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3346                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3347
3348                                                         if(consolechars[0]>0){
3349                                                         for(k=14;k>=1;k--){
3350                                                         for(j=0;j<255;j++){
3351                                                         consoletext[k][j]=consoletext[k-1][j];
3352                                                         }
3353                                                         consolechars[k]=consolechars[k-1];
3354                                                         }
3355                                                         for(j=0;j<255;j++){
3356                                                         consoletext[0][j]=' ';
3357                                                         }
3358                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3359
3360                                                         consolechars[0]=255;
3361                                                         consoleselected=0;
3362                                                         }
3363                                                         }
3364                                                         }
3365
3366                                                         if(Compare(consoletext[0],"host ",0,4)){
3367                                                         unsigned char gameNameStr[32], playerNameStr[32];
3368                                                         char gameName[32];//, playerName[32];
3369                                                         NMUInt32 port;
3370                                                         int players;
3371                                                         int v;
3372
3373                                                         port = 25710;
3374                                                         players =4;
3375
3376                                                         strcpy(gameName, "Host's game");
3377                                                         strcpy(playerName, "Host");
3378                                                         GameC2PStr( gameName, gameNameStr );
3379                                                         GameC2PStr( playerName, playerNameStr );
3380
3381                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3382                                                         if(v)
3383                                                         {
3384                                                         if(consolechars[0]>0){
3385                                                         for(k=14;k>=1;k--){
3386                                                         for(j=0;j<255;j++){
3387                                                         consoletext[k][j]=consoletext[k-1][j];
3388                                                         }
3389                                                         consolechars[k]=consolechars[k-1];
3390                                                         }
3391                                                         for(j=0;j<255;j++){
3392                                                         consoletext[0][j]=' ';
3393                                                         }
3394                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3395
3396                                                         consolechars[0]=255;
3397                                                         consoleselected=0;
3398                                                         }
3399                                                         }
3400                                                         else
3401                                                         {
3402                                                         donesomething=1;
3403                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3404                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3405                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3406
3407                                                         if(consolechars[0]>0){
3408                                                         for(k=14;k>=1;k--){
3409                                                         for(j=0;j<255;j++){
3410                                                         consoletext[k][j]=consoletext[k-1][j];
3411                                                         }
3412                                                         consolechars[k]=consolechars[k-1];
3413                                                         }
3414                                                         for(j=0;j<255;j++){
3415                                                         consoletext[0][j]=' ';
3416                                                         }
3417                                                         sprintf (consoletext[0], "Game hosted");
3418
3419                                                         consolechars[0]=255;
3420                                                         consoleselected=0;
3421                                                         }
3422                                                         }
3423                                                         }
3424                                                         */
3425                                                         if(Compare(consoletext[0],"save ",0,4)){
3426                                                                 mapname[0]=':';
3427                                                                 mapname[1]='D';
3428                                                                 mapname[2]='a';
3429                                                                 mapname[3]='t';
3430                                                                 mapname[4]='a';
3431                                                                 mapname[5]=':';
3432                                                                 mapname[6]='M';
3433                                                                 mapname[7]='a';
3434                                                                 mapname[8]='p';
3435                                                                 mapname[9]='s';
3436                                                                 mapname[10]=':';
3437                                                                 for(j=5;j<consolechars[0];j++){
3438                                                                         mapname[j-5+11]=consoletext[0][j];
3439                                                                 }
3440                                                                 mapname[consolechars[0]-5+11]='\0';
3441
3442                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3443                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3444                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3445
3446                                                                 int mapvers;
3447                                                                 mapvers=12;
3448
3449
3450                                                                 FILE                    *tfile;
3451                                                                 tfile=fopen( ConvertFileName(mapname), "wb" );
3452                                                                 fpackf(tfile, "Bi", mapvers);
3453                                                                 //fpackf(tfile, "Bi", indemo);
3454                                                                 fpackf(tfile, "Bi", maptype);
3455                                                                 fpackf(tfile, "Bi", hostile);
3456                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3457                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3458                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3459                                                                 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);
3460                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3461                                                                         for(j=0;j<player[0].num_weapons;j++){
3462                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3463                                                                         }
3464
3465                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3466                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3467                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3468                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3469
3470                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3471
3472                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3473
3474                                                                         fpackf(tfile, "Bi", numdialogues);
3475                                                                         if(numdialogues)
3476                                                                                 for(k=0;k<numdialogues;k++){
3477                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3478                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3479                                                                                         for(l=0;l<10;l++){
3480                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3481                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3482                                                                                         }
3483                                                                                         if(numdialogueboxes)
3484                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3485                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3486                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3487                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3488                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3489                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3490
3491                                                                                                         templength=strlen(dialoguetext[k][l]);
3492                                                                                                         fpackf(tfile, "Bi",(templength));
3493                                                                                                         for(m=0;m<templength;m++){
3494                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3495                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3496                                                                                                         }
3497
3498                                                                                                         templength=strlen(dialoguename[k][l]);
3499                                                                                                         fpackf(tfile, "Bi",templength);
3500                                                                                                         for(m=0;m<templength;m++){
3501                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3502                                                                                                                 if(dialoguename[k][l][m]=='\0')break;
3503                                                                                                         }
3504
3505                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3506                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3507                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3508
3509                                                                                                         for(m=0;m<10;m++)
3510                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3511
3512                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3513                                                                                                 }
3514                                                                                 }
3515
3516                                                                                 if(player[0].numclothes)
3517                                                                                         for(k=0;k<player[0].numclothes;k++){
3518                                                                                                 templength=strlen(player[0].clothes[k]);
3519                                                                                                 fpackf(tfile, "Bi", templength);
3520                                                                                                 for(l=0;l<templength;l++)
3521                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3522                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
3523                                                                                         }
3524
3525                                                                                         fpackf(tfile, "Bi", environment);
3526
3527                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3528
3529                                                                                         if(objects.numobjects)
3530                                                                                                 for(k=0;k<objects.numobjects;k++){
3531                                                                                                         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]);
3532                                                                                                 }
3533
3534                                                                                                 fpackf(tfile, "Bi", numhotspots);
3535                                                                                                 if(numhotspots)
3536                                                                                                         for(i=0;i<numhotspots;i++){
3537                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3538                                                                                                                 templength=strlen(hotspottext[i]);
3539                                                                                                                 fpackf(tfile, "Bi",templength);
3540                                                                                                                 for(l=0;l<templength;l++)
3541                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3542                                                                                                         }
3543
3544                                                                                                         fpackf(tfile, "Bi", numplayers);
3545                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3546                                                                                                                 for(j=1;j<numplayers;j++){
3547                                                                                                                         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);
3548                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3549                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3550                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3551                                                                                                                                 }
3552                                                                                                                                 if(player[j].numwaypoints<30){
3553                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3554                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3555                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3556                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3557                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3558                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3559                                                                                                                                         }
3560                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3561                                                                                                                                 }
3562                                                                                                                                 else{
3563                                                                                                                                         player[j].numwaypoints=0;
3564                                                                                                                                         player[j].waypoint=0;
3565                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3566                                                                                                                                 }
3567
3568                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3569                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3570                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3571                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3572
3573                                                                                                                                 if(player[j].creature==wolftype){
3574                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3575                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3576                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3577                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3578                                                                                                                                 }
3579
3580                                                                                                                                 if(player[j].creature==rabbittype){
3581                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3582                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3583                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3584                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3585                                                                                                                                 }
3586
3587                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3588
3589
3590
3591                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3592                                                                                                                                 if(player[j].numclothes)
3593                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3594                                                                                                                                                 int templength;
3595                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3596                                                                                                                                                 fpackf(tfile, "Bi", templength);
3597                                                                                                                                                 for(l=0;l<templength;l++)
3598                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3599                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
3600                                                                                                                                         }
3601                                                                                                                 }
3602
3603                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3604                                                                                                                 if(numpathpoints)
3605                                                                                                                         for(j=0;j<numpathpoints;j++){
3606                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3607                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3608                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3609                                                                                                                                 }
3610                                                                                                                         }
3611
3612                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3613
3614
3615                                                                                                                         fclose(tfile);
3616                                                                                                                         donesomething=1;
3617
3618                                                                                                                         /*
3619                                                                                                                         FILE                    *tfile;
3620                                                                                                                         tfile=fopen( mapname, "wb" );
3621                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3622                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3623                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3624                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3625                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3626                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3627                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3628                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3629                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3630                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3631                                                                                                                         }
3632
3633                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3634                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3635                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3636                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3637                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3638                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3639                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3640                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3641                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3642                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3643                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3644
3645                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3646                                                                                                                         if(player[0].numclothes)
3647                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3648                                                                                                                         int templength;
3649                                                                                                                         templength=strlen(player[0].clothes[k]);
3650                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3651                                                                                                                         for(l=0;l<templength;l++)
3652                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3653                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);
3654                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);
3655                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);
3656                                                                                                                         }
3657
3658                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3659
3660                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3661
3662                                                                                                                         for(k=0;k<objects.numobjects;k++){
3663                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3664                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3665                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3666                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3667                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3668                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3669                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3670                                                                                                                         }
3671
3672                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3673                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3674                                                                                                                         for(j=1;j<numplayers;j++){
3675                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3676                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3677                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3678                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3679                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3680                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3681                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3682                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3683                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3684                                                                                                                         }
3685                                                                                                                         if(player[j].numwaypoints<30){
3686                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3687                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3688                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3689                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3690                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3691                                                                                                                         }
3692                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3693                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3694                                                                                                                         }
3695                                                                                                                         else{
3696                                                                                                                         player[j].numwaypoints=0;
3697                                                                                                                         player[j].waypoint=0;
3698                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3699                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3700                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3701                                                                                                                         }
3702                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
3703                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
3704                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
3705                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
3706                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
3707                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
3708                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
3709                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
3710                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
3711                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
3712                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
3713
3714                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
3715                                                                                                                         if(player[j].numclothes)
3716                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3717                                                                                                                         int templength;
3718                                                                                                                         templength=strlen(player[j].clothes[k]);
3719                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3720                                                                                                                         for(l=0;l<templength;l++)
3721                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
3722                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);
3723                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);
3724                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);
3725                                                                                                                         }
3726                                                                                                                         }
3727                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3728                                                                                                                         if(numpathpoints)
3729                                                                                                                         for(j=0;j<numpathpoints;j++){
3730                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
3731                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
3732                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
3733                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3734                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
3735                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3736                                                                                                                         }
3737                                                                                                                         }
3738
3739                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
3740                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
3741                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
3742
3743                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
3744
3745                                                                                                                         fclose(tfile);
3746                                                                                                                         donesomething=1;*/
3747                                                         }
3748                                                         /*
3749                                                         if(Compare(consoletext[0],"save ",0,4)){
3750                                                         mapname[0]=':';
3751                                                         mapname[1]='D';
3752                                                         mapname[2]='a';
3753                                                         mapname[3]='t';
3754                                                         mapname[4]='a';
3755                                                         mapname[5]=':';
3756                                                         mapname[6]='M';
3757                                                         mapname[7]='a';
3758                                                         mapname[8]='p';
3759                                                         mapname[9]='s';
3760                                                         mapname[10]=':';
3761                                                         for(j=5;j<consolechars[0];j++){
3762                                                         mapname[j-5+11]=consoletext[0][j];
3763                                                         }
3764                                                         mapname[consolechars[0]-5+11]='\0';
3765
3766                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3767                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3768                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3769
3770                                                         FILE                    *tfile;
3771                                                         tfile=fopen( mapname, "wb" );
3772                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
3773                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3774                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3775                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3776                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3777                                                         for(j=0;j<player[0].num_weapons;j++){
3778                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3779                                                         }
3780                                                         fwrite( &environment, 1, sizeof(int), tfile );
3781
3782                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3783                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
3784                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
3785                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
3786                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
3787
3788                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3789                                                         if(numplayers>1&&numplayers<maxplayers)
3790                                                         for(j=1;j<numplayers;j++){
3791                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
3792                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3793                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3794                                                         for(k=0;k<player[j].num_weapons;k++){
3795                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3796                                                         }
3797                                                         if(player[j].numwaypoints<30){
3798                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3799                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
3800                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3801                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3802                                                         }
3803                                                         else{
3804                                                         player[j].numwaypoints=0;
3805                                                         player[j].waypoint=0;
3806                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3807                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3808                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3809                                                         }
3810                                                         }
3811                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3812                                                         if(numpathpoints)
3813                                                         for(j=0;j<numpathpoints;j++){
3814                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
3815                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3816                                                         for(k=0;k<numpathpointconnect[j];k++){
3817                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3818                                                         }
3819                                                         }
3820                                                         fclose(tfile);
3821                                                         donesomething=1;
3822                                                         }*/
3823                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
3824                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
3825                                                                 donesomething=1;
3826                                                         }
3827                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
3828                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
3829                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
3830                                                         donesomething=1;
3831                                                         }*/
3832
3833                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
3834                                                                 for(j=6;j<consolechars[0];j++){
3835                                                                         mapname[j-6]=consoletext[0][j];
3836                                                                 }
3837
3838                                                                 tintr=atof(mapname);
3839
3840                                                                 donesomething=1;
3841                                                         }
3842
3843                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
3844                                                                 for(j=6;j<consolechars[0];j++){
3845                                                                         mapname[j-6]=consoletext[0][j];
3846                                                                 }
3847
3848                                                                 player[0].speedmult=atof(mapname);
3849
3850                                                                 donesomething=1;
3851                                                         }
3852
3853                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
3854                                                                 for(j=9;j<consolechars[0];j++){
3855                                                                         mapname[j-9]=consoletext[0][j];
3856                                                                 }
3857
3858                                                                 player[0].power=atof(mapname);
3859
3860                                                                 donesomething=1;
3861                                                         }
3862
3863                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
3864                                                                 for(j=13;j<consolechars[0];j++){
3865                                                                         mapname[j-13]=consoletext[0][j];
3866                                                                 }
3867
3868                                                                 viewdistance=atof(mapname)*100;
3869
3870                                                                 donesomething=1;
3871                                                         }
3872
3873                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
3874                                                                 for(j=10;j<consolechars[0];j++){
3875                                                                         mapname[j-10]=consoletext[0][j];
3876                                                                 }
3877
3878                                                                 fadestart=atof(mapname);
3879
3880                                                                 donesomething=1;
3881                                                         }
3882
3883                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
3884                                                                 for(j=6;j<consolechars[0];j++){
3885                                                                         mapname[j-6]=consoletext[0][j];
3886                                                                 }
3887
3888                                                                 player[0].power=atof(mapname);
3889
3890                                                                 donesomething=1;
3891                                                         }
3892
3893                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
3894                                                                 for(j=6;j<consolechars[0];j++){
3895                                                                         mapname[j-6]=consoletext[0][j];
3896                                                                 }
3897
3898                                                                 slomospeed=atof(mapname);
3899                                                                 slomo=1-slomo;
3900                                                                 slomodelay=1000;
3901
3902                                                                 donesomething=1;
3903                                                         }
3904
3905                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
3906                                                                 for(j=8;j<consolechars[0];j++){
3907                                                                         mapname[j-8]=consoletext[0][j];
3908                                                                 }
3909
3910                                                                 slomofreq=atoi(mapname);
3911
3912                                                                 donesomething=1;
3913                                                         }
3914
3915                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
3916                                                                 for(j=5;j<consolechars[0];j++){
3917                                                                         mapname[j-5]=consoletext[0][j];
3918                                                                 }
3919
3920                                                                 player[0].scale=atof(mapname)*.2;
3921
3922                                                                 donesomething=1;
3923                                                         }
3924
3925                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
3926                                                                 int closest=-1;
3927                                                                 float closestdist=-1;
3928                                                                 float distance;
3929                                                                 if(numplayers>1)
3930                                                                         for(i=1;i<numplayers;i++){
3931                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
3932                                                                                 if(closestdist==-1||distance<closestdist){
3933                                                                                         closestdist=distance;
3934                                                                                         closest=i;
3935                                                                                 }
3936                                                                         }
3937
3938                                                                         for(j=9;j<consolechars[0];j++){
3939                                                                                 mapname[j-9]=consoletext[0][j];
3940                                                                         }
3941
3942                                                                         player[closest].scale=atof(mapname)*.2;
3943
3944                                                                         donesomething=1;
3945                                                         }
3946
3947                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
3948                                                                 int startpoint;
3949                                                                 int alldone;
3950
3951                                                                 int closest=-1;
3952                                                                 float closestdist=-1;
3953                                                                 float distance;
3954                                                                 if(numplayers>1)
3955                                                                         for(i=1;i<numplayers;i++){
3956                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
3957                                                                                 if(closestdist==-1||distance<closestdist){
3958                                                                                         closestdist=distance;
3959                                                                                         closest=i;
3960                                                                                 }
3961                                                                         }
3962
3963                                                                         alldone=0;
3964                                                                         startpoint=15;
3965                                                                         j=startpoint;
3966                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3967                                                                                 mapname[j-startpoint]=consoletext[0][j];
3968                                                                                 j++;
3969                                                                                 if(consoletext[0][j]=='\0')alldone=1;
3970                                                                         }
3971                                                                         mapname[j-startpoint]='\0';
3972
3973                                                                         headprop=atof(mapname);
3974
3975                                                                         j++;
3976                                                                         startpoint=j;
3977                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3978                                                                                 mapname[j-startpoint]=consoletext[0][j];
3979                                                                                 j++;
3980                                                                                 if(consoletext[0][j]=='\0')alldone=1;
3981                                                                         }
3982                                                                         mapname[j-startpoint]='\0';
3983
3984                                                                         bodyprop=atof(mapname);
3985
3986                                                                         j++;
3987                                                                         startpoint=j;
3988                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3989                                                                                 mapname[j-startpoint]=consoletext[0][j];
3990                                                                                 j++;
3991                                                                                 if(consoletext[0][j]=='\0')alldone=1;
3992                                                                         }
3993                                                                         mapname[j-startpoint]='\0';
3994
3995                                                                         armprop=atof(mapname);
3996
3997                                                                         j++;
3998                                                                         startpoint=j;
3999                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4000                                                                                 mapname[j-startpoint]=consoletext[0][j];
4001                                                                                 j++;
4002                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4003                                                                         }
4004                                                                         mapname[j-startpoint]='\0';
4005
4006                                                                         legprop=atof(mapname);
4007
4008                                                                         if(player[closest].creature==wolftype){
4009                                                                                 player[closest].proportionhead=1.1*headprop;
4010                                                                                 player[closest].proportionbody=1.1*bodyprop;
4011                                                                                 player[closest].proportionarms=1.1*armprop;
4012                                                                                 player[closest].proportionlegs=1.1*legprop;
4013                                                                         }
4014
4015                                                                         if(player[closest].creature==rabbittype){
4016                                                                                 player[closest].proportionhead=1.2*headprop;
4017                                                                                 player[closest].proportionbody=1.05*bodyprop;
4018                                                                                 player[closest].proportionarms=1.00*armprop;
4019                                                                                 player[closest].proportionlegs=1.1*legprop;
4020                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4021                                                                         }
4022
4023                                                                         donesomething=1;
4024                                                         }
4025
4026
4027                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4028                                                                 for(i=1;i<numplayers;i++){
4029                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4030                                                                 }
4031
4032                                                                 donesomething=1;
4033                                                         }
4034
4035                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4036                                                                 for(j=9;j<consolechars[0];j++){
4037                                                                         mapname[j-9]=consoletext[0][j];
4038                                                                 }
4039
4040                                                                 tutoriallevel=atoi(mapname);
4041
4042                                                                 donesomething=1;
4043                                                         }
4044
4045
4046                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4047                                                                 for(j=6;j<consolechars[0];j++){
4048                                                                         mapname[j-6]=consoletext[0][j];
4049                                                                 }
4050
4051                                                                 tintg=atof(mapname);
4052
4053                                                                 donesomething=1;
4054                                                         }
4055
4056                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4057                                                                 for(j=6;j<consolechars[0];j++){
4058                                                                         mapname[j-6]=consoletext[0][j];
4059                                                                 }
4060
4061                                                                 tintb=atof(mapname);
4062
4063                                                                 donesomething=1;
4064                                                         }
4065
4066                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4067                                                                 for(j=8;j<consolechars[0];j++){
4068                                                                         mapname[j-8]=consoletext[0][j];
4069                                                                 }
4070
4071                                                                 hostile=atoi(mapname);
4072
4073                                                                 donesomething=1;
4074                                                         }
4075
4076
4077                                                         if(Compare(consoletext[0],"type active ",0,11)){
4078                                                                 editoractive=typeactive;
4079
4080                                                                 donesomething=1;
4081                                                         }
4082
4083                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4084                                                                 indemo=1;
4085                                                                 hotspot[numhotspots]=player[0].coords;
4086                                                                 hotspotsize[numhotspots]=0;
4087                                                                 hotspottype[numhotspots]=-111;
4088                                                                 mapname[0]='\0';
4089                                                                 strcpy(hotspottext[numhotspots],"mapname");
4090                                                                 numhotspots++;
4091
4092                                                                 donesomething=1;
4093                                                         }
4094
4095                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4096                                                                 indemo=0;
4097                                                                 numhotspots--;
4098
4099                                                                 donesomething=1;
4100                                                         }
4101
4102                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4103                                                                 editoractive=typesitting;
4104
4105                                                                 donesomething=1;
4106                                                         }
4107
4108                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4109                                                                 editoractive=typesittingwall;
4110
4111                                                                 donesomething=1;
4112                                                         }
4113
4114                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4115                                                                 editoractive=typesleeping;
4116
4117                                                                 donesomething=1;
4118                                                         }
4119                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4120                                                                 editoractive=typedead1;
4121
4122                                                                 donesomething=1;
4123                                                         }
4124                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4125                                                                 editoractive=typedead2;
4126
4127                                                                 donesomething=1;
4128                                                         }
4129                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4130                                                                 editoractive=typedead3;
4131                                                                 donesomething=1;
4132                                                         }
4133                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4134                                                                 editoractive=typedead4;
4135
4136                                                                 donesomething=1;
4137                                                         }
4138
4139                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4140                                                                 editorpathtype=wpkeepwalking;
4141
4142                                                                 donesomething=1;
4143                                                         }
4144
4145                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4146                                                                 editorpathtype=wppause;
4147
4148                                                                 donesomething=1;
4149                                                         }
4150
4151                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4152                                                                 maptype=mapkilleveryone;
4153
4154                                                                 donesomething=1;
4155                                                         }
4156
4157                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4158                                                                 maptype=mapgosomewhere;
4159
4160                                                                 donesomething=1;
4161                                                         }
4162
4163                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4164                                                                 maptype=mapkillsomeone;
4165
4166                                                                 donesomething=1;
4167
4168                                                         }
4169
4170                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4171                                                                 maptype=mapkillmost;
4172
4173                                                                 donesomething=1;
4174
4175                                                         }
4176
4177                                                         if(Compare(consoletext[0],"hs ",0,2)){
4178                                                                 int startpoint;
4179                                                                 int alldone;
4180
4181                                                                 hotspot[numhotspots]=player[0].coords;
4182
4183                                                                 alldone=0;
4184                                                                 startpoint=3;
4185                                                                 j=startpoint;
4186                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4187                                                                         mapname[j-startpoint]=consoletext[0][j];
4188                                                                         j++;
4189                                                                         if(consoletext[0][j]=='\0')alldone=1;
4190                                                                 }
4191                                                                 mapname[j-startpoint]='\0';
4192
4193                                                                 hotspotsize[numhotspots]=atof(mapname);
4194
4195                                                                 j++;
4196                                                                 startpoint=j;
4197                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4198                                                                         mapname[j-startpoint]=consoletext[0][j];
4199                                                                         j++;
4200                                                                         if(consoletext[0][j]=='\0')alldone=1;
4201                                                                 }
4202                                                                 mapname[j-startpoint]='\0';
4203
4204                                                                 hotspottype[numhotspots]=atoi(mapname);
4205
4206                                                                 j++;
4207                                                                 startpoint=j;
4208                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4209                                                                         mapname[j-startpoint]=consoletext[0][j];
4210                                                                         j++;
4211                                                                         if(consoletext[0][j]=='\0')alldone=1;
4212                                                                 }
4213                                                                 mapname[j-startpoint]='\n';
4214                                                                 mapname[j-startpoint+1]='\0';
4215
4216                                                                 strcpy(hotspottext[numhotspots],mapname);
4217
4218                                                                 numhotspots++;
4219
4220                                                                 donesomething=1;
4221                                                         }
4222
4223                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4224                                                                 int startpoint;
4225                                                                 int alldone;
4226
4227                                                                 alldone=0;
4228                                                                 startpoint=9;
4229                                                                 j=startpoint;
4230                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4231                                                                         mapname[j-startpoint]=consoletext[0][j];
4232                                                                         j++;
4233                                                                         if(consoletext[0][j]=='\0')alldone=1;
4234                                                                 }
4235                                                                 mapname[j-startpoint]='\0';
4236                                                                 startpoint=j+1;
4237
4238                                                                 dialoguetype[numdialogues]=atoi(mapname);
4239
4240                                                                 mapname[0]=':';
4241                                                                 mapname[1]='D';
4242                                                                 mapname[2]='a';
4243                                                                 mapname[3]='t';
4244                                                                 mapname[4]='a';
4245                                                                 mapname[5]=':';
4246                                                                 mapname[6]='D';
4247                                                                 mapname[7]='i';
4248                                                                 mapname[8]='a';
4249                                                                 mapname[9]='l';
4250                                                                 mapname[10]='o';
4251                                                                 mapname[11]='g';
4252                                                                 mapname[12]='u';
4253                                                                 mapname[13]='e';
4254                                                                 mapname[14]='s';
4255                                                                 mapname[15]=':';
4256                                                                 for(j=startpoint;j<consolechars[0];j++){
4257                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4258                                                                 }
4259                                                                 mapname[consolechars[0]-startpoint+16]='.';
4260                                                                 mapname[consolechars[0]-startpoint+17]='t';
4261                                                                 mapname[consolechars[0]-startpoint+18]='x';
4262                                                                 mapname[consolechars[0]-startpoint+19]='t';
4263                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4264
4265                                                                 for(j=0;j<max_dialoguelength;j++){
4266                                                                         for(k=0;k<128;k++){
4267                                                                                 dialoguetext[numdialogues][j][k]='\0';
4268                                                                         }
4269                                                                         for(k=0;k<64;k++){
4270                                                                                 dialoguename[numdialogues][j][k]='\0';
4271                                                                         }
4272                                                                 }
4273
4274                                                                 ifstream ipstream(ConvertFileName(mapname));
4275                                                                 ipstream.ignore(256,':');
4276                                                                 ipstream >> numdialogueboxes[numdialogues];
4277                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4278                                                                         ipstream.ignore(256,':');
4279                                                                         ipstream.ignore(256,':');
4280                                                                         ipstream.ignore(256,' ');
4281                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4282                                                                         ipstream.ignore(256,':');
4283                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4284                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4285                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4286                                                                         ipstream.ignore(256,':');
4287                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4288                                                                         ipstream.ignore(256,':');
4289                                                                         ipstream.ignore(256,' ');
4290                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4291                                                                         for(j=0;j<128;j++){
4292                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4293                                                                         }
4294                                                                         ipstream.ignore(256,':');
4295                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4296                                                                 }
4297
4298                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4299                                                                         for(j=0;j<numplayers;j++){
4300                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4301                                                                         }
4302                                                                 }
4303                                                                 ipstream.close();
4304
4305                                                                 directing=1;
4306                                                                 indialogue=0;
4307                                                                 whichdialogue=numdialogues;
4308
4309
4310                                                                 numdialogues++;
4311
4312                                                                 donesomething=1;
4313                                                         }
4314
4315                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4316                                                                 int startpoint;
4317                                                                 int alldone;
4318                                                                 int whichdi;
4319
4320                                                                 alldone=0;
4321                                                                 startpoint=12;
4322                                                                 j=startpoint;
4323                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4324                                                                         mapname[j-startpoint]=consoletext[0][j];
4325                                                                         j++;
4326                                                                         if(consoletext[0][j]=='\0')alldone=1;
4327                                                                 }
4328                                                                 mapname[j-startpoint]='\0';
4329                                                                 startpoint=j+1;
4330
4331                                                                 whichdi=atoi(mapname);
4332
4333                                                                 mapname[0]=':';
4334                                                                 mapname[1]='D';
4335                                                                 mapname[2]='a';
4336                                                                 mapname[3]='t';
4337                                                                 mapname[4]='a';
4338                                                                 mapname[5]=':';
4339                                                                 mapname[6]='D';
4340                                                                 mapname[7]='i';
4341                                                                 mapname[8]='a';
4342                                                                 mapname[9]='l';
4343                                                                 mapname[10]='o';
4344                                                                 mapname[11]='g';
4345                                                                 mapname[12]='u';
4346                                                                 mapname[13]='e';
4347                                                                 mapname[14]='s';
4348                                                                 mapname[15]=':';
4349                                                                 for(j=startpoint;j<consolechars[0];j++){
4350                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4351                                                                 }
4352                                                                 mapname[consolechars[0]-startpoint+16]='.';
4353                                                                 mapname[consolechars[0]-startpoint+17]='t';
4354                                                                 mapname[consolechars[0]-startpoint+18]='x';
4355                                                                 mapname[consolechars[0]-startpoint+19]='t';
4356                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4357
4358                                                                 for(j=0;j<max_dialoguelength;j++){
4359                                                                         for(k=0;k<128;k++){
4360                                                                                 dialoguetext[whichdi][j][k]='\0';
4361                                                                         }
4362                                                                         for(k=0;k<64;k++){
4363                                                                                 dialoguename[whichdi][j][k]='\0';
4364                                                                         }
4365                                                                 }
4366
4367                                                                 ifstream ipstream(ConvertFileName(mapname));
4368                                                                 ipstream.ignore(256,':');
4369                                                                 ipstream >> numdialogueboxes[whichdi];
4370                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4371                                                                         ipstream.ignore(256,':');
4372                                                                         ipstream.ignore(256,':');
4373                                                                         ipstream.ignore(256,' ');
4374                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4375                                                                         ipstream.ignore(256,':');
4376                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4377                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4378                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4379                                                                         ipstream.ignore(256,':');
4380                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4381                                                                         ipstream.ignore(256,':');
4382                                                                         ipstream.ignore(256,' ');
4383                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4384                                                                         for(j=0;j<128;j++){
4385                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4386                                                                         }
4387                                                                         ipstream.ignore(256,':');
4388                                                                         ipstream >> dialogueboxsound[whichdi][i];
4389                                                                 }
4390
4391                                                                 ipstream.close();
4392
4393                                                                 donesomething=1;
4394                                                         }
4395
4396                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4397                                                                 int startpoint;
4398                                                                 int alldone;
4399                                                                 int whichdi;
4400
4401                                                                 alldone=0;
4402                                                                 startpoint=8;
4403                                                                 j=startpoint;
4404                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4405                                                                         mapname[j-startpoint]=consoletext[0][j];
4406                                                                         j++;
4407                                                                         if(consoletext[0][j]=='\0')alldone=1;
4408                                                                 }
4409                                                                 mapname[j-startpoint]='\0';
4410                                                                 dialoguetype[0]=atoi(mapname);
4411
4412                                                                 startpoint=j+1;
4413
4414                                                                 donesomething=1;
4415                                                         }
4416
4417
4418                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4419                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4420
4421                                                                 donesomething=1;
4422                                                         }
4423
4424                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4425                                                                 numdialogues--;
4426                                                                 if(numdialogues<0)numdialogues=0;
4427
4428                                                                 donesomething=1;
4429                                                         }
4430
4431                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4432                                                                 player[0].immobile=1;
4433                                                                 donesomething=1;
4434                                                         }
4435
4436                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4437                                                                 player[0].immobile=0;
4438                                                                 donesomething=1;
4439                                                         }
4440
4441                                                         if(Compare(consoletext[0],"play ",0,4)){
4442                                                                 int startpoint;
4443                                                                 int alldone;
4444
4445                                                                 alldone=0;
4446                                                                 startpoint=5;
4447                                                                 j=startpoint;
4448                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4449                                                                         mapname[j-startpoint]=consoletext[0][j];
4450                                                                         j++;
4451                                                                         if(consoletext[0][j]=='\0')alldone=1;
4452                                                                 }
4453                                                                 mapname[j-startpoint]='\0';
4454                                                                 startpoint=j+1;
4455
4456                                                                 whichdialogue=atoi(mapname);
4457
4458                                                                 if(numdialogues>whichdialogue){
4459                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4460                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4461                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4462                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4463                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4464                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4465                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4466                                                                         }
4467
4468                                                                         directing=0;
4469                                                                         indialogue=0;
4470
4471                                                                         donesomething=1;
4472
4473                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4474                                                                         float gLoc[3];
4475                                                                         float vel[3];
4476                                                                         XYZ temppos;
4477                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4478                                                                         temppos=temppos-viewer;
4479                                                                         Normalise(&temppos);
4480                                                                         temppos+=viewer;
4481
4482                                                                         gLoc[0]=temppos.x;
4483                                                                         gLoc[1]=temppos.y;
4484                                                                         gLoc[2]=temppos.z;
4485                                                                         vel[0]=0;
4486                                                                         vel[1]=0;
4487                                                                         vel[2]=0;
4488                                                                         int whichsoundplay;
4489                                                                         whichsoundplay=rabbitchitter;
4490                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4491                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4492                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4493                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4494                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4495                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4496                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4497                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4498                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4499                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4500                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4501                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4502                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4503                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4504                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4505                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4506                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4507                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4508                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4509                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4510                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4511                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
4512                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
4513                                                                         //}
4514                                                                 }
4515                                                         }
4516
4517
4518
4519
4520                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4521                                                                 numhotspots--;
4522                                                                 if(numhotspots<0)numhotspots=0;
4523                                                                 donesomething=1;
4524                                                         }
4525
4526
4527                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4528                                                                 int startpoint;
4529                                                                 int alldone;
4530
4531                                                                 alldone=0;
4532                                                                 startpoint=11;
4533                                                                 j=startpoint;
4534                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4535                                                                         mapname[j-startpoint]=consoletext[0][j];
4536                                                                         j++;
4537                                                                         if(consoletext[0][j]=='\0')alldone=1;
4538                                                                 }
4539                                                                 mapname[j-startpoint]='\0';
4540
4541                                                                 headprop=atof(mapname);
4542
4543                                                                 j++;
4544                                                                 startpoint=j;
4545                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4546                                                                         mapname[j-startpoint]=consoletext[0][j];
4547                                                                         j++;
4548                                                                         if(consoletext[0][j]=='\0')alldone=1;
4549                                                                 }
4550                                                                 mapname[j-startpoint]='\0';
4551
4552                                                                 bodyprop=atof(mapname);
4553
4554                                                                 j++;
4555                                                                 startpoint=j;
4556                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4557                                                                         mapname[j-startpoint]=consoletext[0][j];
4558                                                                         j++;
4559                                                                         if(consoletext[0][j]=='\0')alldone=1;
4560                                                                 }
4561                                                                 mapname[j-startpoint]='\0';
4562
4563                                                                 armprop=atof(mapname);
4564
4565                                                                 j++;
4566                                                                 startpoint=j;
4567                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4568                                                                         mapname[j-startpoint]=consoletext[0][j];
4569                                                                         j++;
4570                                                                         if(consoletext[0][j]=='\0')alldone=1;
4571                                                                 }
4572                                                                 mapname[j-startpoint]='\0';
4573
4574                                                                 legprop=atof(mapname);
4575
4576                                                                 if(player[0].creature==wolftype){
4577                                                                         player[0].proportionhead=1.1*headprop;
4578                                                                         player[0].proportionbody=1.1*bodyprop;
4579                                                                         player[0].proportionarms=1.1*armprop;
4580                                                                         player[0].proportionlegs=1.1*legprop;
4581                                                                 }
4582
4583                                                                 if(player[0].creature==rabbittype){
4584                                                                         player[0].proportionhead=1.2*headprop;
4585                                                                         player[0].proportionbody=1.05*bodyprop;
4586                                                                         player[0].proportionarms=1.00*armprop;
4587                                                                         player[0].proportionlegs=1.1*legprop;
4588                                                                         player[0].proportionlegs.y=1.05*legprop;
4589                                                                 }
4590
4591                                                                 donesomething=1;
4592                                                         }
4593
4594                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4595                                                                 for(i=0;i<numplayers;i++){
4596                                                                         if(i>0)player[i].immobile=1;
4597                                                                 }
4598                                                                 donesomething=1;
4599                                                         }
4600
4601
4602                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4603                                                                 player[0].armorhead=1;
4604                                                                 player[0].armorhigh=1;
4605                                                                 player[0].armorlow=1;
4606                                                                 player[0].protectionhead=1;
4607                                                                 player[0].protectionhigh=1;
4608                                                                 player[0].protectionlow=1;
4609                                                                 player[0].metalhead=1;
4610                                                                 player[0].metalhigh=1;
4611                                                                 player[0].metallow=1;
4612                                                                 player[0].power=1;
4613                                                                 player[0].speedmult=1;
4614                                                                 player[0].scale=1;
4615
4616                                                                 if(player[0].creature==wolftype){
4617                                                                         player[0].proportionhead=1.1;
4618                                                                         player[0].proportionbody=1.1;
4619                                                                         player[0].proportionarms=1.1;
4620                                                                         player[0].proportionlegs=1.1;
4621                                                                 }
4622
4623                                                                 if(player[0].creature==rabbittype){
4624                                                                         player[0].proportionhead=1.2;
4625                                                                         player[0].proportionbody=1.05;
4626                                                                         player[0].proportionarms=1.00;
4627                                                                         player[0].proportionlegs=1.1;
4628                                                                         player[0].proportionlegs.y=1.05;
4629                                                                 }
4630
4631                                                                 player[0].numclothes=0;
4632                                                                 LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
4633                                                                                 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4634
4635                                                                 editoractive=typeactive;
4636                                                                 player[0].immobile=0;
4637
4638
4639
4640                                                                 donesomething=1;
4641                                                         }
4642
4643                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4644                                                                 int startpoint;
4645                                                                 int alldone;
4646                                                                 alldone=0;
4647                                                                 startpoint=5;
4648                                                                 j=startpoint;
4649                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4650                                                                         mapname[j-startpoint]=consoletext[0][j];
4651                                                                         j++;
4652                                                                         if(consoletext[0][j]=='\0')alldone=1;
4653                                                                 }
4654                                                                 mapname[j-startpoint]='\0';
4655
4656                                                                 tintr=atof(mapname);
4657
4658                                                                 j++;
4659                                                                 startpoint=j;
4660                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4661                                                                         mapname[j-startpoint]=consoletext[0][j];
4662                                                                         j++;
4663                                                                         if(consoletext[0][j]=='\0')alldone=1;
4664                                                                 }
4665                                                                 mapname[j-startpoint]='\0';
4666
4667                                                                 tintg=atof(mapname);
4668
4669                                                                 j++;
4670                                                                 startpoint=j;
4671                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4672                                                                         mapname[j-startpoint]=consoletext[0][j];
4673                                                                         j++;
4674                                                                         if(consoletext[0][j]=='\0')alldone=1;
4675                                                                 }
4676                                                                 mapname[j-startpoint]='\0';
4677
4678                                                                 tintb=atof(mapname);
4679
4680                                                                 donesomething=1;
4681                                                         }
4682
4683                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
4684                                                                 int startpoint;
4685                                                                 int alldone;
4686                                                                 alldone=0;
4687                                                                 startpoint=9;
4688                                                                 j=startpoint;
4689                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4690                                                                         mapname[j-startpoint]=consoletext[0][j];
4691                                                                         j++;
4692                                                                         if(consoletext[0][j]=='\0')alldone=1;
4693                                                                 }
4694                                                                 mapname[j-startpoint]='\0';
4695
4696                                                                 skyboxr=atof(mapname);
4697
4698                                                                 j++;
4699                                                                 startpoint=j;
4700                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4701                                                                         mapname[j-startpoint]=consoletext[0][j];
4702                                                                         j++;
4703                                                                         if(consoletext[0][j]=='\0')alldone=1;
4704                                                                 }
4705                                                                 mapname[j-startpoint]='\0';
4706
4707                                                                 skyboxg=atof(mapname);
4708
4709                                                                 j++;
4710                                                                 startpoint=j;
4711                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4712                                                                         mapname[j-startpoint]=consoletext[0][j];
4713                                                                         j++;
4714                                                                         if(consoletext[0][j]=='\0')alldone=1;
4715                                                                 }
4716                                                                 mapname[j-startpoint]='\0';
4717
4718                                                                 skyboxb=atof(mapname);
4719
4720                                                                 skyboxlightr=skyboxr;
4721                                                                 skyboxlightg=skyboxg;
4722                                                                 skyboxlightb=skyboxb;
4723
4724                                                                 SetUpLighting();
4725
4726                                                                 //if(skyboxtexture){
4727                                                                 terrain.DoShadows();
4728                                                                 objects.DoShadows();
4729                                                                 /*}
4730                                                                 else terrain.DoLighting();
4731                                                                 */
4732                                                                 donesomething=1;
4733                                                         }
4734
4735                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
4736                                                                 int startpoint;
4737                                                                 int alldone;
4738                                                                 alldone=0;
4739                                                                 startpoint=10;
4740                                                                 j=startpoint;
4741                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4742                                                                         mapname[j-startpoint]=consoletext[0][j];
4743                                                                         j++;
4744                                                                         if(consoletext[0][j]=='\0')alldone=1;
4745                                                                 }
4746                                                                 mapname[j-startpoint]='\0';
4747
4748                                                                 skyboxlightr=atof(mapname);
4749
4750                                                                 j++;
4751                                                                 startpoint=j;
4752                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4753                                                                         mapname[j-startpoint]=consoletext[0][j];
4754                                                                         j++;
4755                                                                         if(consoletext[0][j]=='\0')alldone=1;
4756                                                                 }
4757                                                                 mapname[j-startpoint]='\0';
4758
4759                                                                 skyboxlightg=atof(mapname);
4760
4761                                                                 j++;
4762                                                                 startpoint=j;
4763                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4764                                                                         mapname[j-startpoint]=consoletext[0][j];
4765                                                                         j++;
4766                                                                         if(consoletext[0][j]=='\0')alldone=1;
4767                                                                 }
4768                                                                 mapname[j-startpoint]='\0';
4769
4770                                                                 skyboxlightb=atof(mapname);
4771
4772                                                                 SetUpLighting();
4773
4774                                                                 //if(skyboxtexture){
4775                                                                 terrain.DoShadows();
4776                                                                 objects.DoShadows();
4777                                                                 /*}
4778                                                                 else terrain.DoLighting();
4779                                                                 */
4780                                                                 donesomething=1;
4781                                                         }
4782
4783                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
4784                                                                 skyboxtexture=1-skyboxtexture;
4785
4786                                                                 SetUpLighting();
4787                                                                 //if(skyboxtexture){
4788                                                                 terrain.DoShadows();
4789                                                                 objects.DoShadows();
4790                                                                 /*}
4791                                                                 else terrain.DoLighting();
4792                                                                 */
4793                                                                 donesomething=1;
4794                                                         }
4795
4796                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
4797                                                                 int startpoint;
4798                                                                 int alldone;
4799                                                                 alldone=0;
4800                                                                 startpoint=11;
4801                                                                 j=startpoint;
4802                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4803                                                                         mapname[j-startpoint]=consoletext[0][j];
4804                                                                         j++;
4805                                                                         if(consoletext[0][j]=='\0')alldone=1;
4806                                                                 }
4807                                                                 mapname[j-startpoint]='\0';
4808
4809                                                                 player[0].protectionhead=atof(mapname);
4810
4811                                                                 j++;
4812                                                                 startpoint=j;
4813                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4814                                                                         mapname[j-startpoint]=consoletext[0][j];
4815                                                                         j++;
4816                                                                         if(consoletext[0][j]=='\0')alldone=1;
4817                                                                 }
4818                                                                 mapname[j-startpoint]='\0';
4819
4820                                                                 player[0].protectionhigh=atof(mapname);
4821
4822                                                                 j++;
4823                                                                 startpoint=j;
4824                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4825                                                                         mapname[j-startpoint]=consoletext[0][j];
4826                                                                         j++;
4827                                                                         if(consoletext[0][j]=='\0')alldone=1;
4828                                                                 }
4829                                                                 mapname[j-startpoint]='\0';
4830
4831                                                                 player[0].protectionlow=atof(mapname);
4832
4833                                                                 donesomething=1;
4834                                                         }
4835
4836                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
4837                                                                 int startpoint;
4838                                                                 int alldone;
4839                                                                 alldone=0;
4840                                                                 startpoint=6;
4841                                                                 j=startpoint;
4842                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4843                                                                         mapname[j-startpoint]=consoletext[0][j];
4844                                                                         j++;
4845                                                                         if(consoletext[0][j]=='\0')alldone=1;
4846                                                                 }
4847                                                                 mapname[j-startpoint]='\0';
4848
4849                                                                 player[0].armorhead=atof(mapname);
4850
4851                                                                 j++;
4852                                                                 startpoint=j;
4853                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4854                                                                         mapname[j-startpoint]=consoletext[0][j];
4855                                                                         j++;
4856                                                                         if(consoletext[0][j]=='\0')alldone=1;
4857                                                                 }
4858                                                                 mapname[j-startpoint]='\0';
4859
4860                                                                 player[0].armorhigh=atof(mapname);
4861
4862                                                                 j++;
4863                                                                 startpoint=j;
4864                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4865                                                                         mapname[j-startpoint]=consoletext[0][j];
4866                                                                         j++;
4867                                                                         if(consoletext[0][j]=='\0')alldone=1;
4868                                                                 }
4869                                                                 mapname[j-startpoint]='\0';
4870
4871                                                                 player[0].armorlow=atof(mapname);
4872
4873                                                                 donesomething=1;
4874                                                         }
4875
4876                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
4877                                                                 for(i=0;i<numplayers;i++){
4878                                                                         player[i].protectionhead=1.0;
4879                                                                         player[i].protectionhigh=1.0;
4880                                                                         player[i].protectionlow=1.0;
4881                                                                         player[i].armorhead=1.0;
4882                                                                         player[i].armorhigh=1.0;
4883                                                                         player[i].armorlow=1.0;
4884                                                                 }
4885
4886                                                                 donesomething=1;
4887                                                         }
4888
4889                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
4890                                                                 int closest=-1;
4891                                                                 float closestdist=-1;
4892                                                                 float distance;
4893                                                                 if(numplayers>1)
4894                                                                         for(i=1;i<numplayers;i++){
4895                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4896                                                                                 if(closestdist==-1||distance<closestdist){
4897                                                                                         closestdist=distance;
4898                                                                                         closest=i;
4899                                                                                 }
4900                                                                         }
4901
4902                                                                         int startpoint;
4903                                                                         int alldone;
4904                                                                         alldone=0;
4905                                                                         startpoint=15;
4906                                                                         j=startpoint;
4907                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4908                                                                                 mapname[j-startpoint]=consoletext[0][j];
4909                                                                                 j++;
4910                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4911                                                                         }
4912                                                                         mapname[j-startpoint]='\0';
4913
4914                                                                         player[closest].protectionhead=atof(mapname);
4915
4916                                                                         j++;
4917                                                                         startpoint=j;
4918                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4919                                                                                 mapname[j-startpoint]=consoletext[0][j];
4920                                                                                 j++;
4921                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4922                                                                         }
4923                                                                         mapname[j-startpoint]='\0';
4924
4925                                                                         player[closest].protectionhigh=atof(mapname);
4926
4927                                                                         j++;
4928                                                                         startpoint=j;
4929                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4930                                                                                 mapname[j-startpoint]=consoletext[0][j];
4931                                                                                 j++;
4932                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4933                                                                         }
4934                                                                         mapname[j-startpoint]='\0';
4935
4936                                                                         player[closest].protectionlow=atof(mapname);
4937
4938                                                                         donesomething=1;
4939                                                         }
4940
4941                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
4942                                                                 int closest=-1;
4943                                                                 float closestdist=-1;
4944                                                                 float distance;
4945                                                                 if(numplayers>1)
4946                                                                         for(i=1;i<numplayers;i++){
4947                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4948                                                                                 if(closestdist==-1||distance<closestdist){
4949                                                                                         closestdist=distance;
4950                                                                                         closest=i;
4951                                                                                 }
4952                                                                         }
4953                                                                         int startpoint;
4954                                                                         int alldone;
4955                                                                         alldone=0;
4956                                                                         startpoint=10;
4957                                                                         j=startpoint;
4958                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4959                                                                                 mapname[j-startpoint]=consoletext[0][j];
4960                                                                                 j++;
4961                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4962                                                                         }
4963                                                                         mapname[j-startpoint]='\0';
4964
4965                                                                         player[closest].armorhead=atof(mapname);
4966
4967                                                                         j++;
4968                                                                         startpoint=j;
4969                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4970                                                                                 mapname[j-startpoint]=consoletext[0][j];
4971                                                                                 j++;
4972                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4973                                                                         }
4974                                                                         mapname[j-startpoint]='\0';
4975
4976                                                                         player[closest].armorhigh=atof(mapname);
4977
4978                                                                         j++;
4979                                                                         startpoint=j;
4980                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4981                                                                                 mapname[j-startpoint]=consoletext[0][j];
4982                                                                                 j++;
4983                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4984                                                                         }
4985                                                                         mapname[j-startpoint]='\0';
4986
4987                                                                         player[closest].armorlow=atof(mapname);
4988
4989                                                                         donesomething=1;
4990                                                         }
4991
4992
4993                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
4994                                                                 int startpoint;
4995                                                                 int alldone;
4996                                                                 alldone=0;
4997                                                                 startpoint=6;
4998                                                                 j=startpoint;
4999                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5000                                                                         mapname[j-startpoint]=consoletext[0][j];
5001                                                                         j++;
5002                                                                         if(consoletext[0][j]=='\0')alldone=1;
5003                                                                 }
5004                                                                 mapname[j-startpoint]='\0';
5005
5006                                                                 player[0].metalhead=atof(mapname);
5007
5008                                                                 j++;
5009                                                                 startpoint=j;
5010                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5011                                                                         mapname[j-startpoint]=consoletext[0][j];
5012                                                                         j++;
5013                                                                         if(consoletext[0][j]=='\0')alldone=1;
5014                                                                 }
5015                                                                 mapname[j-startpoint]='\0';
5016
5017                                                                 player[0].metalhigh=atof(mapname);
5018
5019                                                                 j++;
5020                                                                 startpoint=j;
5021                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5022                                                                         mapname[j-startpoint]=consoletext[0][j];
5023                                                                         j++;
5024                                                                         if(consoletext[0][j]=='\0')alldone=1;
5025                                                                 }
5026
5027                                                                 mapname[j-startpoint]='\0';
5028
5029                                                                 player[0].metallow=atof(mapname);
5030
5031                                                                 donesomething=1;
5032                                                         }
5033
5034                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5035                                                                 int closest=-1;
5036                                                                 float closestdist=-1;
5037                                                                 float distance;
5038                                                                 if(numplayers>1)
5039                                                                         for(i=1;i<numplayers;i++){
5040                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5041                                                                                 if(closestdist==-1||distance<closestdist){
5042                                                                                         closestdist=distance;
5043                                                                                         closest=i;
5044                                                                                 }
5045                                                                         }
5046                                                                         player[closest].numclothes=0;
5047                                                                         LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
5048                                                                                         &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5049
5050                                                                         donesomething=1;
5051                                                         }
5052
5053                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5054                                                                 int closest=0;
5055
5056                                                                 player[closest].numclothes=0;
5057                                                                 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
5058                                                                                 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5059                                                                 donesomething=1;
5060                                                         }
5061
5062                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5063                                                                 mapname[0]=':';
5064                                                                 mapname[1]='D';
5065                                                                 mapname[2]='a';
5066                                                                 mapname[3]='t';
5067                                                                 mapname[4]='a';
5068                                                                 mapname[5]=':';
5069                                                                 mapname[6]='T';
5070                                                                 mapname[7]='e';
5071                                                                 mapname[8]='x';
5072                                                                 mapname[9]='t';
5073                                                                 mapname[10]='u';
5074                                                                 mapname[11]='r';
5075                                                                 mapname[12]='e';
5076                                                                 mapname[13]='s';
5077                                                                 mapname[14]=':';
5078                                                                 for(j=8;j<consolechars[0];j++){
5079                                                                         mapname[j-8+15]=consoletext[0][j];
5080                                                                 }
5081                                                                 mapname[consolechars[0]-8+15]='.';
5082                                                                 mapname[consolechars[0]-8+16]='p';
5083                                                                 mapname[consolechars[0]-8+17]='n';
5084                                                                 mapname[consolechars[0]-8+18]='g';
5085                                                                 mapname[consolechars[0]-8+19]='\0';
5086
5087                                                                 //:Data:Textures:Pants.png
5088
5089                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5090                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5091                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5092                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5093                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5094                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5095                                                                         player[0].numclothes++;
5096                                                                 }
5097
5098                                                                 donesomething=1;
5099                                                         }
5100
5101                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5102                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5103
5104                                                                 donesomething=1;
5105                                                         }
5106
5107                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5108                                                                 cellophane=1-cellophane;
5109
5110                                                                 if(cellophane){
5111                                                                         for(i=0;i<numplayers;i++){
5112                                                                                 player[i].proportionhead.z=0;
5113                                                                                 player[i].proportionbody.z=0;
5114                                                                                 player[i].proportionarms.z=0;
5115                                                                                 player[i].proportionlegs.z=0;
5116                                                                         }
5117                                                                 }
5118
5119                                                                 if(!cellophane){
5120                                                                         for(i=0;i<numplayers;i++){
5121                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5122                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5123                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5124                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5125                                                                         }
5126                                                                 }
5127
5128                                                                 donesomething=1;
5129                                                         }
5130
5131                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5132                                                                 mapname[0]=':';
5133                                                                 mapname[1]='D';
5134                                                                 mapname[2]='a';
5135                                                                 mapname[3]='t';
5136                                                                 mapname[4]='a';
5137                                                                 mapname[5]=':';
5138                                                                 mapname[6]='T';
5139                                                                 mapname[7]='e';
5140                                                                 mapname[8]='x';
5141                                                                 mapname[9]='t';
5142                                                                 mapname[10]='u';
5143                                                                 mapname[11]='r';
5144                                                                 mapname[12]='e';
5145                                                                 mapname[13]='s';
5146                                                                 mapname[14]=':';
5147                                                                 for(j=12;j<consolechars[0];j++){
5148                                                                         mapname[j-12+15]=consoletext[0][j];
5149                                                                 }
5150                                                                 mapname[consolechars[0]-12+15]='.';
5151                                                                 mapname[consolechars[0]-12+16]='p';
5152                                                                 mapname[consolechars[0]-12+17]='n';
5153                                                                 mapname[consolechars[0]-12+18]='g';
5154                                                                 mapname[consolechars[0]-12+19]='\0';
5155
5156                                                                 //:Data:Textures:Pants.png
5157                                                                 int closest=-1;
5158                                                                 float closestdist=-1;
5159                                                                 float distance;
5160                                                                 if(numplayers>1)
5161                                                                         for(i=1;i<numplayers;i++){
5162                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5163                                                                                 if(closestdist==-1||distance<closestdist){
5164                                                                                         closestdist=distance;
5165                                                                                         closest=i;
5166                                                                                 }
5167                                                                         }
5168
5169                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5170                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5171                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5172                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5173                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5174                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5175                                                                                 player[closest].numclothes++;
5176                                                                         }
5177
5178                                                                         donesomething=1;
5179                                                         }
5180
5181                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5182                                                                 player[0].skeleton.id=0;
5183                                                                 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);
5184                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5185                                                                 player[0].creature=rabbittype;
5186                                                                 player[0].scale=.2;
5187
5188                                                                 player[0].proportionhead=1.2;
5189                                                                 player[0].proportionbody=1.05;
5190                                                                 player[0].proportionarms=1.00;
5191                                                                 player[0].proportionlegs=1.1;
5192                                                                 player[0].proportionlegs.y=1.05;
5193                                                                 player[0].headless=0;
5194
5195                                                                 player[0].damagetolerance=200;
5196
5197                                                                 donesomething=1;
5198                                                         }
5199                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5200                                                                 player[0].skeleton.id=0;
5201                                                                 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);
5202                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5203                                                                 player[0].creature=wolftype;
5204
5205                                                                 player[0].proportionhead=1.1;
5206                                                                 player[0].proportionbody=1.1;
5207                                                                 player[0].proportionarms=1.1;
5208                                                                 player[0].proportionlegs=1.1;
5209                                                                 player[0].proportionlegs.y=1.1;
5210                                                                 player[0].scale=.23;
5211
5212                                                                 player[0].damagetolerance=300;
5213
5214                                                                 donesomething=1;
5215                                                         }
5216                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5217                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5218                                                         donesomething=1;
5219                                                         }
5220                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5221                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5222                                                         donesomething=1;
5223                                                         }
5224                                                         if(Compare(consoletext[0],"david ",0,5)){
5225                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5226                                                         donesomething=1;
5227                                                         }*/
5228                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5229                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5230                                                                 donesomething=1;
5231                                                         }
5232                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5233                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5234                                                                 donesomething=1;
5235                                                         }
5236                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5237                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5238                                                                 donesomething=1;
5239                                                         }/*
5240                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5241                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5242                                                          donesomething=1;
5243                                                          }*/
5244                                                         if(Compare(consoletext[0],"white ",0,5)){
5245                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5246                                                                 donesomething=1;
5247                                                         }
5248                                                         if(Compare(consoletext[0],"brown ",0,5)){
5249                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5250                                                                 donesomething=1;
5251                                                         }
5252                                                         if(Compare(consoletext[0],"black ",0,5)){
5253                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5254                                                                 donesomething=1;
5255                                                         }
5256                                                         if(consolechars[0]>0){
5257                                                                 for(k=14;k>=1;k--){
5258                                                                         for(j=0;j<255;j++){
5259                                                                                 consoletext[k][j]=consoletext[k-1][j];
5260                                                                         }
5261                                                                         consolechars[k]=consolechars[k-1];
5262                                                                 }
5263                                                                 for(j=0;j<255;j++){
5264                                                                         consoletext[0][j]=' ';
5265                                                                 }
5266                                                                 consolechars[0]=0;
5267                                                                 consoleselected=0;
5268
5269                                                                 if(!donesomething){
5270                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
5271                                                                         OPENAL_SetVolume(channels[consolefailsound], 256);
5272                                                                         OPENAL_SetPaused(channels[consolefailsound], false);
5273                                                                 }
5274                                                         }
5275                                                 }
5276                                         }
5277                                         togglekey[i]=1;
5278                                 }
5279                                 else {
5280                                         togglekey[i]=0;
5281                                         togglekeydelay[i]=0;
5282                                 }
5283                         }
5284
5285                         consoleblinkdelay-=multiplier;
5286                         if(consoleblinkdelay<=0){
5287                                 consoleblinkdelay=.3;
5288                                 consoleblink=1-consoleblink;
5289                         }
5290                 }
5291
5292                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5293                         tryquit=1;
5294                         if(mainmenu==3){
5295                                 if(newdetail>2)newdetail=detail;
5296                                 if(newdetail<0)newdetail=detail;
5297                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5298                                 if(newscreenheight<0)newscreenheight=screenheight;
5299
5300                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5301                                 opstream << "Screenwidth:\n";
5302                                 opstream << newscreenwidth;
5303                                 opstream << "\nScreenheight:\n";
5304                                 opstream << newscreenheight;
5305                                 opstream << "\nMouse sensitivity:\n";
5306                                 opstream << usermousesensitivity;
5307                                 opstream << "\nBlur(0,1):\n";
5308                                 opstream << ismotionblur;
5309                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5310                                 opstream << newdetail;
5311                                 opstream << "\nFloating jump:\n";
5312                                 opstream << floatjump;
5313                                 opstream << "\nMouse jump:\n";
5314                                 opstream << mousejump;
5315                                 opstream << "\nAmbient sound:\n";
5316                                 opstream << ambientsound;
5317                                 opstream << "\nBlood (0,1,2):\n";
5318                                 opstream << bloodtoggle;
5319                                 opstream << "\nAuto slomo:\n";
5320                                 opstream << autoslomo;
5321                                 opstream << "\nFoliage:\n";
5322                                 opstream << foliage;
5323                                 opstream << "\nMusic:\n";
5324                                 opstream << musictoggle;
5325                                 opstream << "\nTrilinear:\n";
5326                                 opstream << trilinear;
5327                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5328                                 opstream << decals;
5329                                 opstream << "\nInvert mouse:\n";
5330                                 opstream << invertmouse;
5331                                 opstream << "\nGamespeed:\n";
5332                                 if(oldgamespeed==0)oldgamespeed=1;
5333                                 opstream << oldgamespeed;
5334                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5335                                 opstream << difficulty;
5336                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5337                                 opstream << damageeffects;
5338                                 opstream << "\nText:\n";
5339                                 opstream << texttoggle;
5340                                 opstream << "\nDebug:\n";
5341                                 opstream << debugmode;
5342                                 opstream << "\nVBL Sync:\n";
5343                                 opstream << vblsync;
5344                                 opstream << "\nShow Points:\n";
5345                                 opstream << showpoints;
5346                                 opstream << "\nAlways Blur:\n";
5347                                 opstream << alwaysblur;
5348                                 opstream << "\nImmediate mode (turn on on G5):\n";
5349                                 opstream << immediate;
5350                                 opstream << "\nVelocity blur:\n";
5351                                 opstream << velocityblur;
5352                             opstream << "\nVolume:\n";
5353                         opstream << volume;
5354                                 opstream << "\nForward key:\n";
5355                                 opstream << KeyToChar(forwardkey);
5356                                 opstream << "\nBack key:\n";
5357                                 opstream << KeyToChar(backkey);
5358                                 opstream << "\nLeft key:\n";
5359                                 opstream << KeyToChar(leftkey);
5360                                 opstream << "\nRight key:\n";
5361                                 opstream << KeyToChar(rightkey);
5362                                 opstream << "\nJump key:\n";
5363                                 opstream << KeyToChar(jumpkey);
5364                                 opstream << "\nCrouch key:\n";
5365                                 opstream << KeyToChar(crouchkey);
5366                                 opstream << "\nDraw key:\n";
5367                                 opstream << KeyToChar(drawkey);
5368                                 opstream << "\nThrow key:\n";
5369                                 opstream << KeyToChar(throwkey);
5370                                 opstream << "\nAttack key:\n";
5371                                 opstream << KeyToChar(attackkey);
5372                                 opstream << "\nChat key:\n";
5373                                 opstream << KeyToChar(chatkey);
5374                                 opstream << "\nDamage bar:\n";
5375                                 opstream << showdamagebar;
5376                                 opstream.close();
5377                         }
5378                 }
5379
5380                 static int oldwinfreeze;
5381                 if(winfreeze&&!oldwinfreeze){
5382                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5383                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
5384                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
5385                         OPENAL_SetPaused(channels[consolesuccesssound], false);
5386                 }
5387                 if(winfreeze==0)oldwinfreeze=winfreeze;
5388                 else oldwinfreeze++;
5389
5390                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5391                         if(winfreeze)winfreeze=0;
5392                         oldjumpkeydown=1;
5393                 }
5394                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5395                         if(winfreeze){
5396                                 mainmenu=9;
5397                                 gameon=0;
5398                         }
5399                 }
5400                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5401                         oldjumpkeydown=1;
5402                 }
5403                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5404
5405                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5406
5407                         static bool oldbuttondialogue;
5408
5409                         if(indialogue!=-1)talkdelay=1;
5410                         talkdelay-=multiplier;
5411
5412                         if(talkdelay<=0)
5413                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5414                                         for(i=0;i<numdialogues;i++){
5415                                                 int realdialoguetype;
5416                                                 bool special;
5417                                                 if(dialoguetype[i]>49){
5418                                                         realdialoguetype=dialoguetype[i]-50;
5419                                                         special=1;
5420                                                 }
5421                                                 else if(dialoguetype[i]>39){
5422                                                         realdialoguetype=dialoguetype[i]-40;
5423                                                         special=1;
5424                                                 }
5425                                                 else if(dialoguetype[i]>29){
5426                                                         realdialoguetype=dialoguetype[i]-30;
5427                                                         special=1;
5428                                                 }
5429                                                 else if(dialoguetype[i]>19){
5430                                                         realdialoguetype=dialoguetype[i]-20;
5431                                                         special=1;
5432                                                 }
5433                                                 else if(dialoguetype[i]>9){
5434                                                         realdialoguetype=dialoguetype[i]-10;
5435                                                         special=1;
5436                                                 }
5437                                                 else {
5438                                                         realdialoguetype=dialoguetype[i];
5439                                                         special=0;
5440                                                 }
5441                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5442                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5443                                                                 whichdialogue=i;
5444                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5445                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5446                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5447                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5448                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5449                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5450                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5451                                                                 }
5452                                                                 directing=0;
5453                                                                 indialogue=0;
5454                                                                 dialoguetime=0;
5455                                                                 dialoguegonethrough[i]++;
5456                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5457                                                                         static float gLoc[3];
5458                                                                         static float vel[3];
5459                                                                         XYZ temppos;
5460                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5461                                                                         temppos=temppos-viewer;
5462                                                                         Normalise(&temppos);
5463                                                                         temppos+=viewer;
5464
5465                                                                         gLoc[0]=temppos.x;
5466                                                                         gLoc[1]=temppos.y;
5467                                                                         gLoc[2]=temppos.z;vel[0]=0;
5468                                                                         vel[1]=0;
5469                                                                         vel[2]=0;
5470                                                                         int whichsoundplay;
5471                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5472                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5473                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5474                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5475                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5476                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5477                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5478                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5479                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5480                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5481                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5482                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5483                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5484                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5485                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5486                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5487                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5488                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5489                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5490                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5491                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
5492                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5493                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
5494                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
5495                                                                 }
5496                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5497                                                         }
5498                                                 }
5499                                         }
5500
5501                                         windvar+=multiplier;
5502                                         smoketex+=multiplier;
5503                                         tutorialstagetime+=multiplier;
5504
5505                                         static float hotspotvisual[40];
5506                                         if(numhotspots){
5507                                                 XYZ hotspotsprite;
5508                                                 if(editorenabled)
5509                                                         for(i=0;i<numhotspots;i++)
5510                                                                 hotspotvisual[i]-=multiplier/320;
5511
5512                                                 for(i=0;i<numhotspots;i++){
5513                                                         //if(hotspottype[i]<=10)
5514                                                         while(hotspotvisual[i]<0){
5515                                                                 hotspotsprite=0;
5516                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5517                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5518                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5519                                                                 hotspotsprite+=hotspot[i];
5520                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5521                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5522                                                         }
5523                                                 }
5524
5525                                                 for(i=0;i<numhotspots;i++){
5526                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5527                                                                 hotspot[i]=player[hotspottype[i]].coords;
5528                                                         }
5529                                                 }
5530                                         }
5531
5532                                         //Tutorial
5533                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5534                                                 tutorialstage++;
5535                                                 tutorialsuccess=0;
5536                                                 if(tutorialstage<=1){
5537                                                         canattack=0;
5538                                                         cananger=0;
5539                                                         reversaltrain=0;
5540                                                 }
5541                                                 if(tutorialstage==1){
5542                                                         tutorialmaxtime=5;
5543                                                 }
5544                                                 if(tutorialstage==2){
5545                                                         tutorialmaxtime=2;
5546                                                 }
5547                                                 if(tutorialstage==3){
5548                                                         tutorialmaxtime=600;
5549                                                 }
5550                                                 if(tutorialstage==4){
5551                                                         tutorialmaxtime=1000;
5552                                                 }
5553                                                 if(tutorialstage==5){
5554                                                         tutorialmaxtime=600;
5555                                                 }
5556                                                 if(tutorialstage==6){
5557                                                         tutorialmaxtime=600;
5558                                                 }
5559                                                 if(tutorialstage==7){
5560                                                         tutorialmaxtime=600;
5561                                                 }
5562                                                 if(tutorialstage==8){
5563                                                         tutorialmaxtime=600;
5564                                                 }
5565                                                 if(tutorialstage==9){
5566                                                         tutorialmaxtime=600;
5567                                                 }
5568                                                 if(tutorialstage==10){
5569                                                         tutorialmaxtime=2;
5570                                                 }
5571                                                 if(tutorialstage==11){
5572                                                         tutorialmaxtime=1000;
5573                                                 }
5574                                                 if(tutorialstage==12){
5575                                                         tutorialmaxtime=1000;
5576                                                 }
5577                                                 if(tutorialstage==13){
5578                                                         tutorialmaxtime=2;
5579                                                 }
5580                                                 if(tutorialstage==14){
5581                                                         tutorialmaxtime=3;
5582
5583                                                         XYZ temp,temp2;
5584
5585                                                         temp.x=1011;
5586                                                         temp.y=84;
5587                                                         temp.z=491;
5588                                                         temp2.x=1025;
5589                                                         temp2.y=75;
5590                                                         temp2.z=447;
5591
5592                                                         player[1].coords=(temp+temp2)/2;
5593
5594                                                         float gLoc[3];
5595                                                         float vel[3];
5596                                                         gLoc[0]=player[1].coords.x;
5597                                                         gLoc[1]=player[1].coords.y;
5598                                                         gLoc[2]=player[1].coords.z;
5599                                                         vel[0]=0;
5600                                                         vel[1]=0;
5601                                                         vel[2]=0;
5602                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5603                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5604                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5605                                                         OPENAL_SetPaused(channels[fireendsound], false);
5606
5607                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5608                                                                 if(Random()%2==0){
5609                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5610                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5611                                                                         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;
5612                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5613                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5614                                                                 }
5615                                                         }
5616
5617                                                 }
5618                                                 if(tutorialstage==15){
5619                                                         tutorialmaxtime=500;
5620                                                 }
5621                                                 if(tutorialstage==16){
5622                                                         tutorialmaxtime=500;
5623                                                 }
5624                                                 if(tutorialstage==17){
5625                                                         tutorialmaxtime=500;
5626                                                 }
5627                                                 if(tutorialstage==18){
5628                                                         tutorialmaxtime=500;
5629                                                 }
5630                                                 if(tutorialstage==19){
5631                                                         tutorialstage=20;
5632                                                         //tutorialmaxtime=500;
5633                                                 }
5634                                                 if(tutorialstage==20){
5635                                                         tutorialmaxtime=500;
5636                                                 }
5637                                                 if(tutorialstage==21){
5638                                                         tutorialmaxtime=500;
5639                                                         if(bonus==cannon){
5640                                                                 bonus=Slicebonus;
5641                                                                 againbonus=1;
5642                                                         }
5643                                                         else againbonus=0;
5644                                                 }
5645                                                 if(tutorialstage==22){
5646                                                         tutorialmaxtime=500;
5647                                                 }
5648                                                 if(tutorialstage==23){
5649                                                         tutorialmaxtime=500;
5650                                                 }
5651                                                 if(tutorialstage==24){
5652                                                         tutorialmaxtime=500;
5653                                                 }
5654                                                 if(tutorialstage==25){
5655                                                         tutorialmaxtime=500;
5656                                                 }
5657                                                 if(tutorialstage==26){
5658                                                         tutorialmaxtime=2;
5659                                                 }
5660                                                 if(tutorialstage==27){
5661                                                         tutorialmaxtime=4;
5662                                                         reversaltrain=1;
5663                                                         cananger=1;
5664                                                         player[1].aitype=attacktypecutoff;
5665                                                 }
5666                                                 if(tutorialstage==28){
5667                                                         tutorialmaxtime=400;
5668                                                 }
5669                                                 if(tutorialstage==29){
5670                                                         tutorialmaxtime=400;
5671                                                         player[0].escapednum=0;
5672                                                 }
5673                                                 if(tutorialstage==30){
5674                                                         tutorialmaxtime=4;
5675                                                         reversaltrain=0;
5676                                                         cananger=0;
5677                                                         player[1].aitype=passivetype;
5678                                                 }
5679                                                 if(tutorialstage==31){
5680                                                         tutorialmaxtime=13;
5681                                                 }
5682                                                 if(tutorialstage==32){
5683                                                         tutorialmaxtime=8;
5684                                                 }
5685                                                 if(tutorialstage==33){
5686                                                         tutorialmaxtime=400;
5687                                                         cananger=1;
5688                                                         canattack=1;
5689                                                         player[1].aitype=attacktypecutoff;
5690                                                 }
5691                                                 if(tutorialstage==34){
5692                                                         tutorialmaxtime=400;
5693                                                 }
5694                                                 if(tutorialstage==35){
5695                                                         tutorialmaxtime=400;
5696                                                 }
5697                                                 if(tutorialstage==36){
5698                                                         tutorialmaxtime=2;
5699                                                         reversaltrain=0;
5700                                                         cananger=0;
5701                                                         player[1].aitype=passivetype;
5702                                                 }
5703                                                 if(tutorialstage==37){
5704                                                         damagedealt=0;
5705                                                         damagetaken=0;
5706                                                         tutorialmaxtime=50;
5707                                                         cananger=1;
5708                                                         canattack=1;
5709                                                         player[1].aitype=attacktypecutoff;
5710                                                 }
5711                                                 if(tutorialstage==38){
5712                                                         tutorialmaxtime=4;
5713                                                         canattack=0;
5714                                                         cananger=0;
5715                                                         player[1].aitype=passivetype;
5716                                                 }
5717                                                 if(tutorialstage==39){
5718                                                         XYZ temp,temp2;
5719
5720                                                         temp.x=1011;
5721                                                         temp.y=84;
5722                                                         temp.z=491;
5723                                                         temp2.x=1025;
5724                                                         temp2.y=75;
5725                                                         temp2.z=447;
5726
5727
5728                                                         weapons.owner[weapons.numweapons]=-1;
5729                                                         weapons.type[weapons.numweapons]=knife;
5730                                                         weapons.damage[weapons.numweapons]=0;
5731                                                         weapons.mass[weapons.numweapons]=1;
5732                                                         weapons.tipmass[weapons.numweapons]=1.2;
5733                                                         weapons.length[weapons.numweapons]=.25;
5734                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
5735                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
5736
5737                                                         weapons.velocity[weapons.numweapons]=0.1;
5738                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
5739                                                         weapons.missed[weapons.numweapons]=1;
5740                                                         weapons.hitsomething[weapons.numweapons]=0;
5741                                                         weapons.freetime[weapons.numweapons]=0;
5742                                                         weapons.firstfree[weapons.numweapons]=1;
5743                                                         weapons.physics[weapons.numweapons]=1;
5744
5745                                                         weapons.numweapons++;
5746                                                 }
5747                                                 if(tutorialstage==40){
5748                                                         tutorialmaxtime=300;
5749                                                 }
5750                                                 if(tutorialstage==41){
5751                                                         tutorialmaxtime=300;
5752                                                 }
5753                                                 if(tutorialstage==42){
5754                                                         tutorialmaxtime=8;
5755                                                 }
5756                                                 if(tutorialstage==43){
5757                                                         tutorialmaxtime=300;
5758                                                 }
5759                                                 if(tutorialstage==44){
5760                                                         weapons.owner[0]=1;
5761                                                         player[0].weaponactive=-1;
5762                                                         player[0].num_weapons=0;
5763                                                         player[1].weaponactive=0;
5764                                                         player[1].num_weapons=1;
5765                                                         player[1].weaponids[0]=0;
5766
5767                                                         cananger=1;
5768                                                         canattack=1;
5769                                                         player[1].aitype=attacktypecutoff;
5770
5771                                                         tutorialmaxtime=300;
5772                                                 }
5773                                                 if(tutorialstage==45){
5774                                                         weapons.owner[0]=1;
5775                                                         player[0].weaponactive=-1;
5776                                                         player[0].num_weapons=0;
5777                                                         player[1].weaponactive=0;
5778                                                         player[1].num_weapons=1;
5779                                                         player[1].weaponids[0]=0;
5780
5781                                                         tutorialmaxtime=300;
5782                                                 }
5783                                                 if(tutorialstage==46){
5784                                                         weapons.owner[0]=1;
5785                                                         player[0].weaponactive=-1;
5786                                                         player[0].num_weapons=0;
5787                                                         player[1].weaponactive=0;
5788                                                         player[1].num_weapons=1;
5789                                                         player[1].weaponids[0]=0;
5790
5791                                                         weapons.type[0]=sword;
5792
5793                                                         tutorialmaxtime=300;
5794                                                 }
5795
5796                                                 if(tutorialstage==47){
5797                                                         tutorialmaxtime=10;
5798
5799                                                         XYZ temp,temp2;
5800
5801                                                         temp.x=1011;
5802                                                         temp.y=84;
5803                                                         temp.z=491;
5804                                                         temp2.x=1025;
5805                                                         temp2.y=75;
5806                                                         temp2.z=447;
5807
5808                                                         weapons.owner[weapons.numweapons]=-1;
5809                                                         weapons.type[weapons.numweapons]=sword;
5810                                                         weapons.damage[weapons.numweapons]=0;
5811                                                         weapons.mass[weapons.numweapons]=1;
5812                                                         weapons.tipmass[weapons.numweapons]=1.2;
5813                                                         weapons.length[weapons.numweapons]=.25;
5814                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
5815                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
5816
5817                                                         weapons.velocity[weapons.numweapons]=0.1;
5818                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
5819                                                         weapons.missed[weapons.numweapons]=1;
5820                                                         weapons.hitsomething[weapons.numweapons]=0;
5821                                                         weapons.freetime[weapons.numweapons]=0;
5822                                                         weapons.firstfree[weapons.numweapons]=1;
5823                                                         weapons.physics[weapons.numweapons]=1;
5824
5825                                                         weapons.owner[0]=1;
5826                                                         weapons.owner[1]=0;
5827                                                         player[0].weaponactive=0;
5828                                                         player[0].num_weapons=1;
5829                                                         player[0].weaponids[0]=1;
5830                                                         player[1].weaponactive=0;
5831                                                         player[1].num_weapons=1;
5832                                                         player[1].weaponids[0]=0;
5833
5834                                                         weapons.numweapons++;
5835                                                 }
5836                                                 if(tutorialstage==48){
5837                                                         canattack=0;
5838                                                         cananger=0;
5839                                                         player[1].aitype=passivetype;
5840
5841                                                         tutorialmaxtime=15;
5842
5843                                                         weapons.owner[0]=1;
5844                                                         weapons.owner[1]=0;
5845                                                         player[0].weaponactive=0;
5846                                                         player[0].num_weapons=1;
5847                                                         player[0].weaponids[0]=1;
5848                                                         player[1].weaponactive=0;
5849                                                         player[1].num_weapons=1;
5850                                                         player[1].weaponids[0]=0;
5851
5852                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
5853                                                         else weapons.type[0]=staff;
5854
5855                                                         weapons.numweapons++;
5856                                                 }
5857                                                 if(tutorialstage==49){
5858                                                         canattack=0;
5859                                                         cananger=0;
5860                                                         player[1].aitype=passivetype;
5861
5862                                                         tutorialmaxtime=200;
5863
5864                                                         weapons.position[1]=1000;
5865                                                         weapons.tippoint[1]=1000;
5866
5867                                                         weapons.numweapons=1;
5868                                                         weapons.owner[0]=0;
5869                                                         player[1].weaponactive=-1;
5870                                                         player[1].num_weapons=0;
5871                                                         player[0].weaponactive=0;
5872                                                         player[0].num_weapons=1;
5873                                                         player[0].weaponids[0]=0;
5874
5875                                                         weapons.type[0]=knife;
5876
5877                                                         weapons.numweapons++;
5878                                                 }
5879                                                 if(tutorialstage==50){
5880                                                         tutorialmaxtime=8;
5881
5882                                                         XYZ temp,temp2;
5883                                                         float gLoc[3];
5884                                                         float vel[3];
5885                                                         gLoc[0]=player[1].coords.x;
5886                                                         gLoc[1]=player[1].coords.y;
5887                                                         gLoc[2]=player[1].coords.z;
5888                                                         vel[0]=0;
5889                                                         vel[1]=0;
5890                                                         vel[2]=0;
5891                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5892                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5893                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5894                                                         OPENAL_SetPaused(channels[fireendsound], false);
5895
5896                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5897                                                                 if(Random()%2==0){
5898                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5899                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5900                                                                         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;
5901                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5902                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5903                                                                 }
5904                                                         }
5905
5906                                                         player[1].num_weapons=0;
5907                                                         player[1].weaponstuck=-1;
5908                                                         player[1].weaponactive=-1;
5909
5910                                                         weapons.numweapons=0;
5911
5912                                                         weapons.owner[0]=-1;
5913                                                         weapons.velocity[0]=0.1;
5914                                                         weapons.tipvelocity[0]=-0.1;
5915                                                         weapons.missed[0]=1;
5916                                                         weapons.hitsomething[0]=0;
5917                                                         weapons.freetime[0]=0;
5918                                                         weapons.firstfree[0]=1;
5919                                                         weapons.physics[0]=1;
5920                                                 }
5921                                                 if(tutorialstage==51){
5922                                                         tutorialmaxtime=80000;
5923                                                 }
5924                                                 if(tutorialstage<=51)tutorialstagetime=0;
5925                                         }
5926
5927                                         //Tutorial success
5928                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
5929                                                 if(tutorialstage==3){
5930                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
5931                                                 }
5932                                                 if(tutorialstage==4){
5933                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
5934                                                 }
5935                                                 if(tutorialstage==5){
5936                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
5937                                                 }
5938                                                 if(tutorialstage==6){
5939                                                         if(player[0].isCrouch())tutorialsuccess=1;
5940                                                 }
5941                                                 if(tutorialstage==7){
5942                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
5943                                                 }
5944                                                 if(tutorialstage==8){
5945                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
5946                                                 }
5947                                                 if(tutorialstage==9){
5948                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
5949                                                 }
5950                                                 if(tutorialstage==11){
5951                                                         if(player[0].isWallJump())tutorialsuccess=1;
5952                                                 }
5953                                                 if(tutorialstage==12){
5954                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
5955                                                 }
5956                                                 if(tutorialstage==15){
5957                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
5958                                                 }
5959                                                 if(tutorialstage==16){
5960                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
5961                                                 }
5962                                                 if(tutorialstage==17){
5963                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
5964                                                 }
5965                                                 if(tutorialstage==18){
5966                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
5967                                                 }
5968                                                 if(tutorialstage==19){
5969                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
5970                                                 }
5971                                                 if(tutorialstage==20){
5972                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
5973                                                 }
5974                                                 if(tutorialstage==21){
5975                                                         if(bonus==cannon)tutorialsuccess=1;
5976                                                 }
5977                                                 if(tutorialstage==22){
5978                                                         if(bonus==spinecrusher)tutorialsuccess=1;
5979                                                 }
5980                                                 if(tutorialstage==23){
5981                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
5982                                                 }
5983                                                 if(tutorialstage==24){
5984                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
5985                                                 }
5986                                                 if(tutorialstage==25){
5987                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
5988                                                 }
5989                                                 if(tutorialstage==28){
5990                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
5991                                                 }
5992                                                 if(tutorialstage==29){
5993                                                         if(player[0].escapednum==2){
5994                                                                 tutorialsuccess=1;
5995                                                                 reversaltrain=0;
5996                                                                 cananger=0;
5997                                                                 player[1].aitype=passivetype;
5998                                                         }
5999                                                 }
6000                                                 if(tutorialstage==33){
6001                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6002                                                 }
6003                                                 if(tutorialstage==34){
6004                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6005                                                 }
6006                                                 if(tutorialstage==35){
6007                                                         if(animation[player[0].targetanimation].attack==reversal){
6008                                                                 tutorialsuccess=1;
6009                                                                 reversaltrain=0;
6010                                                                 cananger=0;
6011                                                                 player[1].aitype=passivetype;
6012                                                         }
6013                                                 }
6014                                                 if(tutorialstage==40){
6015                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6016                                                 }
6017                                                 if(tutorialstage==41){
6018                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6019                                                 }
6020                                                 if(tutorialstage==43){
6021                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6022                                                 }
6023                                                 if(tutorialstage==44){
6024                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6025                                                 }
6026                                                 if(tutorialstage==45){
6027                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6028                                                 }
6029                                                 if(tutorialstage==46){
6030                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6031                                                 }
6032                                                 if(tutorialstage==49){
6033                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6034                                                 }
6035                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6036
6037
6038                                                 if(tutorialstagetime==tutorialmaxtime-3){
6039                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6040                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6041                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6042                                                 }
6043
6044                                                 if(tutorialsuccess>=1){
6045                                                         if(tutorialstage==34||tutorialstage==35)
6046                                                                 tutorialstagetime=tutorialmaxtime-1;
6047                                                 }
6048                                         }
6049
6050                                         if(tutoriallevel){
6051                                                 if(tutorialstage<14||tutorialstage>=50){
6052                                                         player[1].coords.y=300;
6053                                                         player[1].velocity=0;
6054                                                 }
6055                                         }
6056
6057                                         if(tutoriallevel!=1){
6058                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6059                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6060                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6061                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6062                                                 }
6063                                         }
6064                                         else
6065                                                 if(bonustime==0){
6066                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6067                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6068                                                         OPENAL_SetPaused(channels[fireendsound], false);
6069                                                 }
6070                                                 if(bonustime==0){
6071                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6072                                                         else bonusnum[bonus]+=0.15;
6073                                                         if(tutoriallevel)bonusvalue=0;
6074                                                         bonusvalue/=bonusnum[bonus];
6075                                                         bonustotal+=bonusvalue;
6076                                                 }
6077                                                 bonustime+=multiplier;
6078
6079                                                 if(environment==snowyenvironment){
6080                                                         precipdelay-=multiplier;
6081                                                         while(precipdelay<0){
6082                                                                 precipdelay+=.04;
6083                                                                 if(!detail)precipdelay+=.04;
6084                                                                 XYZ footvel,footpoint;
6085
6086                                                                 footvel=0;
6087                                                                 footpoint=viewer+viewerfacing*6;
6088                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6089                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6090                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6091                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6092                                                         }
6093                                                 }
6094                                                 for(k=0;k<numplayers;k++){
6095                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6096                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6097
6098                                                         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){
6099                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6100                                                                 else if(player[k].rotation>player[k].targetrotation){
6101                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6102                                                                 }
6103                                                                 else if(player[k].rotation<player[k].targetrotation){
6104                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6105                                                                 }
6106                                                         }
6107
6108
6109                                                         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))){
6110                                                                 player[k].turnspeed*=2;
6111                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6112                                                                 else if(player[k].rotation>player[k].targetrotation){
6113                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6114                                                                 }
6115                                                                 else if(player[k].rotation<player[k].targetrotation){
6116                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6117                                                                 }
6118                                                                 player[k].turnspeed/=2;
6119                                                         }
6120
6121                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6122                                                                 player[k].turnspeed*=4;
6123                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6124                                                                 else if(player[k].rotation>player[k].targetrotation){
6125                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6126                                                                 }
6127                                                                 else if(player[k].rotation<player[k].targetrotation){
6128                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6129                                                                 }
6130                                                                 player[k].turnspeed/=4;
6131                                                         }
6132
6133                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6134                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6135
6136                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6137                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6138                                                                         bool tempcollide=0;
6139
6140                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6141                                                                         if(player[k].collide>1)player[k].collide=1;
6142                                                                         player[k].collide-=multiplier*30;
6143
6144                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6145                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6146                                                                         }
6147                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6148                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6149                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6150                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6151                                                                                                 lowpoint=player[k].coords;
6152                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6153                                                                                                 else lowpoint.y+=1.3;
6154                                                                                                 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){
6155                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6156                                                                                                 }
6157                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6158                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6159                                                                                                 */
6160                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6161                                                                                                         flatfacing=lowpoint-player[k].coords;
6162                                                                                                         player[k].coords=lowpoint;
6163                                                                                                         player[k].coords.y-=1.3;
6164                                                                                                         player[k].collide=1;
6165                                                                                                         tempcollide=1;
6166                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6167                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6168                                                                                                                 tempcoords1=lowpoint;
6169                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6170                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6171                                                                                                                         player[k].target=0;
6172                                                                                                                         player[k].targetanimation=walljumpleftanim;
6173                                                                                                                         player[k].targetframe=0;
6174                                                                                                                         float gLoc[3];
6175                                                                                                                         float vel[3];
6176                                                                                                                         gLoc[0]=player[k].coords.x;
6177                                                                                                                         gLoc[1]=player[k].coords.y;
6178                                                                                                                         gLoc[2]=player[k].coords.z;
6179                                                                                                                         vel[0]=0;
6180                                                                                                                         vel[1]=0;
6181                                                                                                                         vel[2]=0;
6182                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6183                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6184                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6185                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6186                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6187
6188                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6189                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6190                                                                                                                         player[k].rotation*=360/6.28;
6191                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6192                                                                                                                         player[k].targetrotation=player[k].rotation;
6193                                                                                                                         player[k].lowrotation=player[k].rotation;
6194                                                                                                                         if(k==0)numwallflipped++;
6195                                                                                                                 }
6196                                                                                                                 else
6197                                                                                                                 {
6198                                                                                                                         lowpoint=tempcoords1;
6199                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6200                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6201                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6202                                                                                                                                 player[k].target=0;
6203                                                                                                                                 player[k].targetanimation=walljumprightanim;
6204                                                                                                                                 player[k].targetframe=0;
6205                                                                                                                                 float gLoc[3];
6206                                                                                                                                 float vel[3];
6207                                                                                                                                 gLoc[0]=player[k].coords.x;
6208                                                                                                                                 gLoc[1]=player[k].coords.y;
6209                                                                                                                                 gLoc[2]=player[k].coords.z;
6210                                                                                                                                 vel[0]=0;
6211                                                                                                                                 vel[1]=0;
6212                                                                                                                                 vel[2]=0;
6213                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6214                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6215                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6216                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6217                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6218
6219                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6220                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6221                                                                                                                                 player[k].rotation*=360/6.28;
6222                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6223                                                                                                                                 player[k].targetrotation=player[k].rotation;
6224                                                                                                                                 player[k].lowrotation=player[k].rotation;
6225                                                                                                                                 if(k==0)numwallflipped++;
6226                                                                                                                         }
6227                                                                                                                         else
6228                                                                                                                         {
6229                                                                                                                                 lowpoint=tempcoords1;
6230                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6231                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6232                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6233                                                                                                                                         player[k].target=0;
6234                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6235                                                                                                                                         player[k].targetframe=0;
6236                                                                                                                                         float gLoc[3];
6237                                                                                                                                         float vel[3];
6238                                                                                                                                         gLoc[0]=player[k].coords.x;
6239                                                                                                                                         gLoc[1]=player[k].coords.y;
6240                                                                                                                                         gLoc[2]=player[k].coords.z;
6241                                                                                                                                         vel[0]=0;
6242                                                                                                                                         vel[1]=0;
6243                                                                                                                                         vel[2]=0;
6244                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6245                                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6246                                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6247                                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6248                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6249
6250                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6251                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6252                                                                                                                                         player[k].rotation*=360/6.28;
6253                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6254                                                                                                                                         player[k].targetrotation=player[k].rotation;
6255                                                                                                                                         player[k].lowrotation=player[k].rotation;
6256                                                                                                                                         if(k==0)numwallflipped++;
6257                                                                                                                                 }
6258                                                                                                                                 else
6259                                                                                                                                 {
6260                                                                                                                                         lowpoint=tempcoords1;
6261                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6262                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6263                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6264                                                                                                                                                 player[k].target=0;
6265                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6266                                                                                                                                                 player[k].targetframe=0;
6267                                                                                                                                                 float gLoc[3];
6268                                                                                                                                                 float vel[3];
6269                                                                                                                                                 gLoc[0]=player[k].coords.x;
6270                                                                                                                                                 gLoc[1]=player[k].coords.y;
6271                                                                                                                                                 gLoc[2]=player[k].coords.z;
6272                                                                                                                                                 vel[0]=0;
6273                                                                                                                                                 vel[1]=0;
6274                                                                                                                                                 vel[2]=0;
6275                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6276                                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6277                                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6278                                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6279                                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6280
6281                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6282                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6283                                                                                                                                                 player[k].rotation*=360/6.28;
6284                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6285                                                                                                                                                 player[k].rotation+=180;
6286                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6287                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6288                                                                                                                                                 if(k==0)numwallflipped++;
6289                                                                                                                                         }
6290                                                                                                                                 }
6291                                                                                                                         }
6292                                                                                                                 }
6293                                                                                                         }
6294                                                                                                 }
6295                                                                                         }
6296                                                                                         else if(objects.type[i]==rocktype){
6297                                                                                                 lowpoint2=player[k].coords;
6298                                                                                                 lowpoint=player[k].coords;
6299                                                                                                 lowpoint.y+=2;
6300                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6301                                                                                                         player[k].coords=colpoint;
6302                                                                                                         player[k].collide=1;
6303                                                                                                         tempcollide=1;
6304
6305                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6306                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6307
6308                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6309                                                                                                                 player[k].target=0;
6310                                                                                                                 player[k].targetframe=0;
6311                                                                                                                 player[k].onterrain=1;
6312
6313                                                                                                                 if(player[k].id==0){
6314                                                                                                                         OPENAL_SetPaused(channels[whooshsound], true);
6315                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
6316                                                                                                                 }
6317
6318                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6319                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6320                                                                                                                         player[k].targetanimation=player[k].getLanding();
6321                                                                                                                         float gLoc[3];
6322                                                                                                                         float vel[3];
6323                                                                                                                         gLoc[0]=player[k].coords.x;
6324                                                                                                                         gLoc[1]=player[k].coords.y;
6325                                                                                                                         gLoc[2]=player[k].coords.z;
6326                                                                                                                         vel[0]=player[k].velocity.x;
6327                                                                                                                         vel[1]=player[k].velocity.y;
6328                                                                                                                         vel[2]=player[k].velocity.z;
6329                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6330                                                                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
6331                                                                                                                         OPENAL_SetVolume(channels[landsound], 128);
6332                                                                                                                         OPENAL_SetPaused(channels[landsound], false);
6333                                                                                                                         if(k==0){
6334                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6335                                                                                                                                 envsoundvol[numenvsounds]=16;
6336                                                                                                                                 envsoundlife[numenvsounds]=.4;
6337                                                                                                                                 numenvsounds++;
6338                                                                                                                         }
6339
6340                                                                                                                 }
6341                                                                                                         }
6342                                                                                                 }
6343                                                                                         }
6344                                                                                 }
6345                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6346                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6347                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6348                                                                                                 lowpoint=player[k].coords;
6349                                                                                                 lowpoint.y+=1.35;
6350                                                                                                 if(objects.type[i]!=rocktype)
6351                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6352                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
6353                                                                                                                 player[k].coords=lowpoint;
6354                                                                                                                 player[k].coords.y-=1.35;
6355                                                                                                                 player[k].collide=1;
6356
6357                                                                                                                 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)){
6358                                                                                                                         lowpoint=player[k].coords;
6359                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6360                                                                                                                         lowpoint=player[k].coords;
6361                                                                                                                         lowpoint.y+=.05;
6362                                                                                                                         facing=0;
6363                                                                                                                         facing.z=-1;
6364                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6365                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6366                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6367                                                                                                                         if(whichhit!=-1){
6368                                                                                                                                 lowpoint=player[k].coords;
6369                                                                                                                                 lowpoint.y+=.1;
6370                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6371                                                                                                                                 lowpoint2=lowpoint;
6372                                                                                                                                 lowpointtarget2=lowpointtarget;
6373                                                                                                                                 lowpoint3=lowpoint;
6374                                                                                                                                 lowpointtarget3=lowpointtarget;
6375                                                                                                                                 lowpoint4=lowpoint;
6376                                                                                                                                 lowpointtarget4=lowpointtarget;
6377                                                                                                                                 lowpoint5=lowpoint;
6378                                                                                                                                 lowpointtarget5=lowpointtarget;
6379                                                                                                                                 lowpoint6=lowpoint;
6380                                                                                                                                 lowpointtarget6=lowpointtarget;
6381                                                                                                                                 lowpoint7=lowpoint;
6382                                                                                                                                 lowpointtarget7=lowpoint;
6383                                                                                                                                 lowpoint2.x+=.1;
6384                                                                                                                                 lowpointtarget2.x+=.1;
6385                                                                                                                                 lowpoint3.z+=.1;
6386                                                                                                                                 lowpointtarget3.z+=.1;
6387                                                                                                                                 lowpoint4.x-=.1;
6388                                                                                                                                 lowpointtarget4.x-=.1;
6389                                                                                                                                 lowpoint5.z-=.1;
6390                                                                                                                                 lowpointtarget5.z-=.1;
6391                                                                                                                                 lowpoint6.y+=45/13;
6392                                                                                                                                 lowpointtarget6.y+=45/13;
6393                                                                                                                                 lowpointtarget6+=facing*.6;
6394                                                                                                                                 lowpointtarget7.y+=90/13;
6395                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6396                                                                                                                                 if(objects.friction[i]>.5)
6397                                                                                                                                         if(whichhit!=-1){
6398                                                                                                                                                 //if(k==0){
6399                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6400                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6401                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6402                                                                                                                                                                 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)
6403                                                                                                                                                                         for(j=0;j<45;j++){
6404                                                                                                                                                                                 lowpoint=player[k].coords;
6405                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6406                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6407                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6408                                                                                                                                                                                         if(j<=6){
6409                                                                                                                                                                                                 j=100;
6410                                                                                                                                                                                         }
6411                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6412                                                                                                                                                                                         j=100;
6413                                                                                                                                                                                         }*/
6414                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6415                                                                                                                                                                                                 j=100;
6416                                                                                                                                                                                         }
6417                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6418                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6419                                                                                                                                                                                                 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)*/){
6420                                                                                                                                                                                                         lowpoint=player[k].coords;
6421                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6422                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6423                                                                                                                                                                                                         flatfacing=player[k].coords;
6424                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6425                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6426                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6427
6428                                                                                                                                                                                                         if(j>10||!player[k].isRun()){
6429                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6430                                                                                                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6431                                                                                                                                                                                                                 }
6432                                                                                                                                                                                                                 float gLoc[3];
6433                                                                                                                                                                                                                 float vel[3];
6434                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6435                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6436                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6437                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6438                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6439                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6440                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
6441                                                                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6442                                                                                                                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
6443                                                                                                                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
6444
6445                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6446                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6447                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6448                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6449                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6450                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6451
6452                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6453                                                                                                                                                                                                                 player[k].velocity=0;
6454
6455                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6456                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6457                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6458                                                                                                                                                                                                                         player[k].jumppower=0;
6459                                                                                                                                                                                                                         player[k].jumpclimb=1;
6460                                                                                                                                                                                                                 }
6461                                                                                                                                                                                                                 player[k].transspeed=6;
6462                                                                                                                                                                                                                 player[k].target=0;
6463
6464                                                                                                                                                                                                                 //player[k].currentframe=1;
6465                                                                                                                                                                                                                 player[k].targetframe=1;
6466                                                                                                                                                                                                                 if(j>25){
6467                                                                                                                                                                                                                         //player[k].currentframe=0;
6468                                                                                                                                                                                                                         player[k].targetframe=0;
6469                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6470                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6471                                                                                                                                                                                                                         player[k].jumppower=0;
6472                                                                                                                                                                                                                 }
6473                                                                                                                                                                                                         }
6474                                                                                                                                                                                                         j=100;
6475                                                                                                                                                                                                 }
6476                                                                                                                                                                                         }
6477                                                                                                                                                                                 }
6478                                                                                                                                                                         }
6479                                                                                                                                                                         //}
6480                                                                                                                                         }
6481                                                                                                                         }
6482                                                                                                                 }
6483                                                                                                         }
6484                                                                                         }
6485                                                                                         if(player[k].collide<=0){
6486                                                                                                 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()){
6487                                                                                                         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)){
6488                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6489                                                                                                                 player[k].targetanimation=jumpdownanim;
6490                                                                                                                 player[k].targetframe=0;
6491                                                                                                                 player[k].target=0;
6492
6493                                                                                                                 float gLoc[3];
6494                                                                                                                 float vel[3];
6495                                                                                                                 gLoc[0]=player[k].coords.x;
6496                                                                                                                 gLoc[1]=player[k].coords.y;
6497                                                                                                                 gLoc[2]=player[k].coords.z;
6498                                                                                                                 vel[0]=player[k].velocity.x;
6499                                                                                                                 vel[1]=player[k].velocity.y;
6500                                                                                                                 vel[2]=player[k].velocity.z;
6501                                                                                                                 if(k==0){
6502                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
6503                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6504                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
6505                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
6506                                                                                                                 }
6507                                                                                                         }
6508                                                                                                         player[k].velocity.y+=gravity;
6509                                                                                                 }
6510                                                                                         }
6511                                                                 }
6512                                                         }
6513                                                         player[k].realoldcoords=player[k].coords;
6514                                                 }
6515
6516                                                 static XYZ oldviewer;
6517
6518                                                 if(indialogue==-1){
6519                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6520                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6521                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6522                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6523                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6524                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6525                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6526                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6527                                                 }
6528                                                 else
6529                                                 {
6530                                                         player[0].forwardkeydown=0;
6531                                                         player[0].leftkeydown=0;
6532                                                         player[0].backkeydown=0;
6533                                                         player[0].rightkeydown=0;
6534                                                         player[0].jumpkeydown=0;
6535                                                         player[0].crouchkeydown=0;
6536                                                         player[0].drawkeydown=0;
6537                                                         player[0].throwkeydown=0;
6538                                                 }
6539
6540                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6541
6542
6543                                                 static bool endkeydown;
6544                                                 if(indialogue!=-1){
6545                                                         cameramode=1;
6546                                                         if(directing){
6547                                                                 facing=0;
6548                                                                 facing.z=-1;
6549
6550                                                                 facing=DoRotation(facing,-rotation2,0,0);
6551                                                                 facing=DoRotation(facing,0,0-rotation,0);
6552
6553                                                                 flatfacing=0;
6554                                                                 flatfacing.z=-1;
6555
6556                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6557
6558                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6559                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6560                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6561                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6562                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6563                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6564                                                                 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)
6565                                                                         ||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)
6566                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6567                                                                                 int whichend;
6568                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6569                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6570                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6571                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6572                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6573                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6574                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6575                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6576                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6577                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6578                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6579                                                                                 if(whichend!=-1){
6580                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6581                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6582                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6583                                                                                 }
6584                                                                                 if(whichend==-1){
6585                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6586                                                                                 }
6587                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6588                                                                                         indialogue=-1;
6589                                                                                         directing=0;
6590                                                                                         cameramode=0;
6591                                                                                 }
6592                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6593                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6594                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6595                                                                                 indialogue++;
6596                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6597                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6598                                                                                                 static float gLoc[3];
6599                                                                                                 static float vel[3];
6600                                                                                                 XYZ temppos;
6601                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6602                                                                                                 temppos=temppos-viewer;
6603                                                                                                 Normalise(&temppos);
6604                                                                                                 temppos+=viewer;
6605
6606                                                                                                 gLoc[0]=temppos.x;
6607                                                                                                 gLoc[1]=temppos.y;
6608                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
6609                                                                                                 vel[1]=0;
6610                                                                                                 vel[2]=0;
6611                                                                                                 int whichsoundplay;
6612                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6613                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6614                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6615                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6616                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6617                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6618                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6619                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6620                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6621                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6622                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6623                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6624                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6625                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6626                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6627                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6628                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6629                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6630                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6631                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6632                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6633                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6634                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6635                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6636                                                                                         }
6637                                                                                 }
6638
6639                                                                                 for(j=0;j<numplayers;j++){
6640                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6641                                                                                 }
6642
6643                                                                                 endkeydown=1;
6644                                                                         }
6645                                                                         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)
6646                                                                                 ||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)
6647                                                                                 )){
6648                                                                                         int whichend;
6649                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
6650                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
6651                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
6652                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
6653                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
6654                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
6655                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
6656                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
6657                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
6658                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
6659                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
6660                                                                                 }
6661                                                                                 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)
6662                                                                                         &&!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)
6663                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6664                                                                                                 endkeydown=0;
6665                                                                                         }
6666                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6667                                                                                                 indialogue=-1;
6668                                                                                                 directing=0;
6669                                                                                                 cameramode=0;
6670                                                                                         }
6671                                                         }
6672                                                         if(!directing){
6673                                                                 OPENAL_SetPaused(channels[whooshsound], true);
6674                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
6675                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
6676                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
6677                                                                 }
6678                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6679                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6680                                                                 if(dialoguetime>0.5)
6681                                                                         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)
6682                                                                                 ||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)
6683                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
6684                                                                                         indialogue++;
6685                                                                                         endkeydown=1;
6686                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
6687                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6688                                                                                                         static float gLoc[3];
6689                                                                                                         static float vel[3];
6690                                                                                                         XYZ temppos;
6691                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6692                                                                                                         temppos=temppos-viewer;
6693                                                                                                         Normalise(&temppos);
6694                                                                                                         temppos+=viewer;
6695
6696                                                                                                         gLoc[0]=temppos.x;
6697                                                                                                         gLoc[1]=temppos.y;
6698                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
6699                                                                                                         vel[1]=0;
6700                                                                                                         vel[2]=0;
6701                                                                                                         int whichsoundplay;
6702                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6703                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6704                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6705                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6706                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6707                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6708                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6709                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6710                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6711                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6712                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6713                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6714                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6715                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6716                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6717                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6718                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6719                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6720                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6721                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6722                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
6723                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
6724                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6725                                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6726                                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6727                                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6728                                                                                                         }
6729                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
6730                                                                                                                 hotspot[numhotspots]=player[0].coords;
6731                                                                                                                 hotspotsize[numhotspots]=10;
6732                                                                                                                 hotspottype[numhotspots]=-1;
6733
6734                                                                                                                 numhotspots++;
6735                                                                                                         }
6736                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
6737                                                                                                                 hostile=1;
6738                                                                                                         }
6739
6740                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
6741                                                                                                                 indialogue=-1;
6742                                                                                                                 directing=0;
6743                                                                                                                 cameramode=0;
6744                                                                                                         }
6745                                                                                                 }
6746                                                                                         }
6747                                                                                 }
6748                                                                                 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)
6749                                                                                         &&!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)
6750                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6751                                                                                                 endkeydown=0;
6752                                                                                         }
6753                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6754                                                                                                 indialogue=-1;
6755                                                                                                 directing=0;
6756                                                                                                 cameramode=0;
6757                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6758                                                                                                         hostile=1;
6759                                                                                                 }
6760                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6761                                                                                                         windialogue=1;
6762                                                                                                 }
6763                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6764                                                                                                         hostile=1;
6765                                                                                                         for(i=1;i<numplayers;i++){
6766                                                                                                                 player[i].aitype = attacktypecutoff;
6767                                                                                                         }
6768                                                                                                 }
6769                                                                                         }
6770                                                         }
6771                                                 }
6772
6773                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
6774                                                 else oldbuttondialogue=1;
6775
6776                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
6777
6778                                                 //Net updates
6779
6780                                                 /*keyrefreshdelay-=multiplier;
6781                                                 bigrefreshdelay-=multiplier;
6782
6783                                                 if(keyrefreshdelay<=0){
6784                                                 static int concat[4];
6785
6786                                                 concat[0]=player[0].forwardkeydown;
6787                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
6788                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
6789                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
6790                                                 concat[0]=concat[0]*2+player[0].backkeydown;
6791                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
6792                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
6793                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
6794
6795                                                 concat[1]=player[0].crouchtogglekeydown;
6796                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
6797                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
6798                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
6799                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
6800                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
6801
6802                                                 //concat[2]=(char)((int)(rotation/2)%180);
6803
6804                                                 //concat[3]=(char)((int)(rotation2/2)%180);
6805
6806                                                 chatname[0]=concat[0]-128;
6807                                                 chatname[1]=concat[1]-128;
6808                                                 //chatname[2]=concat[2]-128;
6809                                                 //chatname[3]=concat[3]-128;
6810                                                 int temppoint=2;
6811                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
6812                                                 temppoint+=sizeof(float);
6813                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
6814                                                 temppoint+=sizeof(float);
6815
6816                                                 chatname[temppoint]='\0';
6817
6818                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
6819                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
6820                                                 //keyrefreshdelay=.01;
6821                                                 keyrefreshdelay=.03;
6822                                                 }
6823
6824                                                 if(bigrefreshdelay<=0){
6825                                                 for(i=0;i<1;i++){
6826                                                 /*int temppoint=0;
6827                                                 memcpy(chatname+temppoint,&i,sizeof(int));
6828                                                 temppoint+=sizeof(int);
6829                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
6830                                                 temppoint+=sizeof(float);
6831                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
6832                                                 temppoint+=sizeof(float);
6833                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
6834                                                 temppoint+=sizeof(float);
6835                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
6836                                                 temppoint+=sizeof(float);
6837                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
6838                                                 temppoint+=sizeof(float);
6839                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
6840                                                 temppoint+=sizeof(int);
6841                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
6842                                                 temppoint+=sizeof(int);
6843                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
6844                                                 temppoint+=sizeof(float);
6845                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
6846                                                 temppoint+=sizeof(float);
6847                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
6848                                                 temppoint+=sizeof(float);
6849                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
6850                                                 temppoint+=sizeof(int);
6851                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
6852                                                 temppoint+=sizeof(int);
6853                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
6854                                                 temppoint+=sizeof(float);
6855                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
6856                                                 temppoint+=sizeof(float);
6857                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
6858                                                 temppoint+=sizeof(float);
6859                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
6860                                                 temppoint+=sizeof(int);
6861                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
6862                                                 temppoint+=sizeof(int);
6863                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
6864                                                 temppoint+=sizeof(int);
6865                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
6866                                                 temppoint+=sizeof(int);
6867                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
6868                                                 temppoint+=sizeof(int);
6869                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
6870                                                 temppoint+=sizeof(int);
6871                                                 chatname[temppoint]='\0';
6872
6873                                                 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);
6874                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
6875                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
6876
6877                                                 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);
6878
6879                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
6880                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
6881                                                 }
6882                                                 //bigrefreshdelay=.02;
6883                                                 bigrefreshdelay=.1;
6884                                                 }
6885                                                 }*/
6886
6887                                                 if(!player[0].jumpkeydown){
6888                                                         player[0].jumptogglekeydown=0;
6889                                                 }
6890                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
6891
6892
6893                                                 dialoguetime+=multiplier;
6894                                                 skybox.cloudmove+=multiplier;
6895                                                 hawkrotation+=multiplier*25;
6896                                                 realhawkcoords=0;
6897                                                 realhawkcoords.x=25;
6898                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6899                                                 hawkcalldelay-=multiplier/2;
6900
6901                                                 if(hawkcalldelay<=0)
6902                                                 {
6903                                                         static float gLoc[3];
6904                                                         static float vel[3];
6905                                                         gLoc[0]=realhawkcoords.x;
6906                                                         gLoc[1]=realhawkcoords.y;
6907                                                         gLoc[2]=realhawkcoords.z;
6908                                                         vel[0]=0;
6909                                                         vel[1]=0;
6910                                                         vel[2]=0;
6911                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, true);
6912                                                         OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
6913                                                         OPENAL_SetVolume(channels[hawksound], 128);
6914                                                         OPENAL_SetPaused(channels[hawksound], false);
6915
6916                                                         hawkcalldelay=16+abs(Random()%8);
6917                                                 }
6918                                                 static float temptexdetail;
6919
6920
6921                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
6922                                                         player[0].damagetolerance=200000;
6923                                                         player[0].damage=0;
6924                                                         player[0].burnt=0;
6925                                                         player[0].permanentdamage=0;
6926                                                         player[0].superpermanentdamage=0;
6927                                                         /*
6928                                                         int whichchar;
6929                                                         whichchar = abs(Random()%7);
6930                                                         registrationname[whichchar]+=1;
6931                                                         */
6932                                                 }
6933
6934                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
6935                                                         environment++;
6936                                                         if(environment>2)environment=0;
6937                                                         Setenvironment(environment);
6938
6939                                                         envtogglekeydown=1;
6940                                                 }
6941
6942
6943                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
6944                                                         envtogglekeydown=0;
6945                                                 }
6946
6947                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
6948                                                         cameramode=1-cameramode;
6949                                                         cameratogglekeydown=1;
6950                                                 }
6951
6952                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
6953                                                         cameratogglekeydown=0;
6954                                                 }
6955
6956                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
6957                                                         if(player[0].num_weapons>0){
6958                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
6959                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
6960                                                                 else weapons.type[player[0].weaponids[0]]=sword;
6961                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
6962                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
6963                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
6964                                                                         weapons.length[player[0].weaponids[0]]=.8;
6965                                                                 }
6966                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
6967                                                                         weapons.mass[player[0].weaponids[0]]=2;
6968                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
6969                                                                         weapons.length[player[0].weaponids[0]]=1.5;
6970                                                                 }
6971
6972                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
6973                                                                         weapons.mass[player[0].weaponids[0]]=1;
6974                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
6975                                                                         weapons.length[player[0].weaponids[0]]=.25;
6976                                                                 }
6977                                                         }
6978
6979                                                         /*for(i=0;i<objects.numobjects;i++){
6980                                                         if(objects.type[i]==treeleavestype){
6981                                                         for(j=0;j<objects.numobjects;j++){
6982                                                         if(objects.type[j]==treetrunktype)
6983                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
6984                                                         objects.scale[i]=objects.scale[j];
6985                                                         }
6986                                                         }
6987                                                         }*/
6988                                                         detailtogglekeydown=1;
6989                                                 }
6990
6991                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
6992                                                         int closest=-1;
6993                                                         float closestdist=-1;
6994                                                         float distance;
6995                                                         if(numplayers>1)
6996                                                                 for(i=1;i<numplayers;i++){
6997                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
6998                                                                         if(closestdist==-1||distance<closestdist){
6999                                                                                 closestdist=distance;
7000                                                                                 closest=i;
7001                                                                         }
7002                                                                 }
7003                                                                 if(closest!=-1){
7004                                                                         if(player[closest].num_weapons)
7005                                                                         {
7006                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7007                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7008                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7009                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7010                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7011                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7012                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7013                                                                                 }
7014                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7015                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7016                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7017                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7018                                                                                 }
7019                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7020                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7021                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7022                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7023                                                                                 }
7024                                                                         }
7025                                                                         if(!player[closest].num_weapons)
7026                                                                         {
7027                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7028                                                                                 weapons.owner[weapons.numweapons]=closest;
7029                                                                                 weapons.type[weapons.numweapons]=knife;
7030                                                                                 weapons.damage[weapons.numweapons]=0;
7031                                                                                 weapons.numweapons++;
7032                                                                                 player[closest].num_weapons=1;
7033                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7034                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7035                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7036                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7037                                                                                 }
7038                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7039                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7040                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7041                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7042                                                                                 }
7043                                                                         }
7044                                                                 }
7045                                                                 detailtogglekeydown=1;
7046                                                 }
7047
7048                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7049                                                         int closest=-1;
7050                                                         float closestdist=-1;
7051                                                         float distance;
7052                                                         if(numplayers>1)
7053                                                                 for(i=1;i<numplayers;i++){
7054                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7055                                                                         if(closestdist==-1||distance<closestdist){
7056                                                                                 closestdist=distance;
7057                                                                                 closest=i;
7058                                                                         }
7059                                                                 }
7060
7061                                                                 player[closest].rotation+=multiplier*50;
7062                                                                 player[closest].targetrotation=player[closest].rotation;
7063                                                 }
7064
7065
7066                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7067                                                         int closest=-1;
7068                                                         float closestdist=-1;
7069                                                         float distance;
7070                                                         if(numplayers>1)
7071                                                                 for(i=1;i<numplayers;i++){
7072                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7073                                                                         if(closestdist==-1||distance<closestdist){
7074                                                                                 closestdist=distance;
7075                                                                                 closest=i;
7076                                                                         }
7077                                                                 }
7078                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7079
7080                                                                 if(closest!=-1){
7081                                                                         player[closest].whichskin++;
7082                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7083                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7084
7085                                                                         LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
7086                                                                                         &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7087                                                                 }
7088
7089                                                                 if(player[closest].numclothes){
7090                                                                         for(i=0;i<player[closest].numclothes;i++){
7091                                                                                 tintr=player[closest].clothestintr[i];
7092                                                                                 tintg=player[closest].clothestintg[i];
7093                                                                                 tintb=player[closest].clothestintb[i];
7094                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7095                                                                         }
7096                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7097                                                                 }
7098
7099                                                                 detailtogglekeydown=1;
7100                                                 }
7101
7102                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7103                                                         int closest=-1;
7104                                                         float closestdist=-1;
7105                                                         float distance;
7106                                                         if(numplayers>1)
7107                                                                 for(i=1;i<numplayers;i++){
7108                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7109                                                                         if(closestdist==-1||distance<closestdist){
7110                                                                                 closestdist=distance;
7111                                                                                 closest=i;
7112                                                                         }
7113                                                                 }
7114                                                                 if(closest!=-1){
7115                                                                         if(player[closest].creature==wolftype){
7116                                                                                 headprop=player[closest].proportionhead.x/1.1;
7117                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7118                                                                                 armprop=player[closest].proportionarms.x/1.1;
7119                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7120                                                                         }
7121
7122                                                                         if(player[closest].creature==rabbittype){
7123                                                                                 headprop=player[closest].proportionhead.x/1.2;
7124                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7125                                                                                 armprop=player[closest].proportionarms.x/1.00;
7126                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7127                                                                         }
7128
7129
7130                                                                         if(player[closest].creature==rabbittype){
7131                                                                                 player[closest].skeleton.id=closest;
7132                                                                                 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);
7133                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7134                                                                                 player[closest].whichskin=0;
7135                                                                                 player[closest].creature=wolftype;
7136
7137                                                                                 player[closest].proportionhead=1.1;
7138                                                                                 player[closest].proportionbody=1.1;
7139                                                                                 player[closest].proportionarms=1.1;
7140                                                                                 player[closest].proportionlegs=1.1;
7141                                                                                 player[closest].proportionlegs.y=1.1;
7142                                                                                 player[closest].scale=.23*5*player[0].scale;
7143
7144                                                                                 player[closest].damagetolerance=300;
7145                                                                         }
7146                                                                         else
7147                                                                         {
7148                                                                                 player[closest].skeleton.id=closest;
7149                                                                                 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);
7150                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7151                                                                                 player[closest].whichskin=0;
7152                                                                                 player[closest].creature=rabbittype;
7153
7154                                                                                 player[closest].proportionhead=1.2;
7155                                                                                 player[closest].proportionbody=1.05;
7156                                                                                 player[closest].proportionarms=1.00;
7157                                                                                 player[closest].proportionlegs=1.1;
7158                                                                                 player[closest].proportionlegs.y=1.05;
7159                                                                                 player[closest].scale=.2*5*player[0].scale;
7160
7161                                                                                 player[closest].damagetolerance=200;
7162                                                                         }
7163
7164                                                                         if(player[closest].creature==wolftype){
7165                                                                                 player[closest].proportionhead=1.1*headprop;
7166                                                                                 player[closest].proportionbody=1.1*bodyprop;
7167                                                                                 player[closest].proportionarms=1.1*armprop;
7168                                                                                 player[closest].proportionlegs=1.1*legprop;
7169                                                                         }
7170
7171                                                                         if(player[closest].creature==rabbittype){
7172                                                                                 player[closest].proportionhead=1.2*headprop;
7173                                                                                 player[closest].proportionbody=1.05*bodyprop;
7174                                                                                 player[closest].proportionarms=1.00*armprop;
7175                                                                                 player[closest].proportionlegs=1.1*legprop;
7176                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7177                                                                         }
7178
7179                                                                 }
7180                                                                 detailtogglekeydown=1;
7181                                                 }
7182
7183                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7184                                                         detailtogglekeydown=0;
7185                                                 }
7186
7187                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7188                                                         slomo=1-slomo;
7189                                                         slomodelay=1000;
7190                                                         slomotogglekeydown=1;
7191                                                 }
7192
7193
7194                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7195                                                         int closest=-1;
7196                                                         float closestdist=-1;
7197                                                         float distance;
7198                                                         XYZ flatfacing2,flatvelocity2;
7199                                                         XYZ blah;
7200                                                         if(numplayers>1)
7201                                                                 for(i=1;i<numplayers;i++){
7202                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7203                                                                         if(distance<144&&!player[i].headless)
7204                                                                                 if(closestdist==-1||distance<closestdist){
7205                                                                                         closestdist=distance;
7206                                                                                         closest=i;
7207                                                                                         blah = player[i].coords;
7208                                                                                 }
7209                                                                 }
7210
7211                                                                 if(closest!=-1){
7212                                                                         XYZ headspurtdirection;
7213                                                                         int i = player[closest].skeleton.jointlabels[head];
7214                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7215                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7216                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7217                                                                                 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;
7218                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7219                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7220                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7221                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7222                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7223                                                                                 Normalise(&headspurtdirection);
7224                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7225                                                                                 flatvelocity2+=headspurtdirection*8;
7226                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7227                                                                         }
7228                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7229
7230                                                                         float gLoc[3];
7231                                                                         float vel[3];
7232                                                                         gLoc[0]=blah.x;
7233                                                                         gLoc[1]=blah.y;
7234                                                                         gLoc[2]=blah.z;
7235                                                                         vel[0]=0;
7236                                                                         vel[1]=0;
7237                                                                         vel[2]=0;
7238                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7239                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7240                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7241                                                                         OPENAL_SetPaused(channels[splattersound], false);
7242
7243                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7244                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7245                                                                         OPENAL_SetVolume(channels[breaksound2], 100);
7246                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7247
7248                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7249                                                                         player[closest].RagDoll(0);
7250                                                                         player[closest].dead=2;
7251                                                                         player[closest].headless=1;
7252                                                                         player[closest].DoBloodBig(3,165);
7253
7254                                                                         camerashake+=.3;
7255                                                                 }
7256
7257                                                                 explodetogglekeydown=1;
7258                                                 }
7259
7260                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7261                                                         int closest=-1;
7262                                                         float closestdist=-1;
7263                                                         float distance;
7264                                                         XYZ flatfacing2,flatvelocity2;
7265                                                         XYZ blah;
7266                                                         if(numplayers>1)
7267                                                                 for(i=1;i<numplayers;i++){
7268                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7269                                                                         if(distance<144)
7270                                                                                 if(closestdist==-1||distance<closestdist){
7271                                                                                         closestdist=distance;
7272                                                                                         closest=i;
7273                                                                                         blah=player[i].coords;
7274                                                                                 }
7275                                                                 }
7276
7277                                                                 if(closest!=-1){
7278                                                                         float gLoc[3];
7279                                                                         float vel[3];
7280                                                                         gLoc[0]=blah.x;
7281                                                                         gLoc[1]=blah.y;
7282                                                                         gLoc[2]=blah.z;
7283                                                                         vel[0]=0;
7284                                                                         vel[1]=0;
7285                                                                         vel[2]=0;
7286
7287                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7288                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7289                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7290                                                                         OPENAL_SetPaused(channels[splattersound], false);
7291
7292                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7293                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7294                                                                         OPENAL_SetVolume(channels[breaksound2], 600);
7295                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7296
7297                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7298                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7299                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7300                                                                                 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;
7301                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7302                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7303                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7304                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7305                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7306                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7307                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7308                                                                         }
7309
7310                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7311                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7312                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7313                                                                                 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;
7314                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7315                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7316                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7317                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7318                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7319                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7320                                                                         }
7321
7322                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7323                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7324                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7325                                                                                 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;
7326                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7327                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7328                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7329                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7330                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7331                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7332                                                                         }
7333
7334                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7335                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7336                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7337                                                                                 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;
7338                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7339                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7340                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7341                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7342                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7343                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7344                                                                         }
7345
7346                                                                         XYZ temppos;
7347                                                                         for(j=0;j<numplayers; j++){
7348                                                                                 if(j!=closest){
7349                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7350                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7351                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7352                                                                                                 player[j].skeleton.longdead=0;
7353                                                                                                 player[j].RagDoll(0);
7354                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7355                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7356                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7357                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7358                                                                                                                 Normalise(&flatvelocity2);
7359                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7360                                                                                                         }
7361                                                                                                 }
7362                                                                                         }
7363                                                                                 }
7364                                                                         }
7365
7366                                                                         player[closest].DoDamage(10000);
7367                                                                         player[closest].RagDoll(0);
7368                                                                         player[closest].dead=2;
7369                                                                         player[closest].coords=20;
7370                                                                         player[closest].skeleton.free=2;
7371
7372                                                                         camerashake+=.6;
7373
7374                                                                 }
7375
7376                                                                 explodetogglekeydown=1;
7377                                                 }
7378
7379                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7380                                                         explodetogglekeydown=0;
7381                                                 }
7382
7383                                                 /*
7384                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7385                                                 FILE                    *tfile;
7386                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7387                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7388                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7389                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7390                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7391                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7392                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7393
7394                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7395                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7396                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7397                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7398                                                 for(j=0;j<player[0].num_weapons;j++){
7399                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7400                                                 }
7401                                                 fwrite( &environment, 1, sizeof(int), tfile );
7402
7403                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7404                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7405                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7406                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7407                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7408
7409                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7410                                                 if(numplayers>1&&numplayers<maxplayers)
7411                                                 for(i=1;i<numplayers;i++){
7412                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7413                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7414                                                 for(j=0;j<player[i].num_weapons;j++){
7415                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7416                                                 }
7417                                                 if(player[i].numwaypoints<30){
7418                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7419                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7420                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7421                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7422                                                 }
7423                                                 else{
7424                                                 player[i].numwaypoints=0;
7425                                                 player[i].waypoint=0;
7426                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7427                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7428                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7429                                                 }
7430                                                 }
7431
7432                                                 fclose(tfile);
7433
7434                                                 slomotogglekeydown=1;
7435                                                 }*/
7436
7437                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7438                                                         slomotogglekeydown=0;
7439                                                 }
7440
7441
7442                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7443                                                         player[0].onfire=1-player[0].onfire;
7444                                                         if(player[0].onfire){
7445                                                                 player[0].CatchFire();
7446                                                         }
7447                                                         if(!player[0].onfire){
7448                                                                 float gLoc[3];
7449                                                                 float vel[3];
7450                                                                 gLoc[0]=player[0].coords.x;
7451                                                                 gLoc[1]=player[0].coords.y;
7452                                                                 gLoc[2]=player[0].coords.z;
7453                                                                 vel[0]=0;
7454                                                                 vel[1]=0;
7455                                                                 vel[2]=0;
7456                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7457                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7458                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
7459                                                                 OPENAL_SetPaused(channels[fireendsound], false);
7460                                                                 OPENAL_SetPaused(channels[stream_firesound], true);
7461                                                         }
7462                                                         slomotogglekeydown=1;
7463                                                 }
7464                                                 /*
7465                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7466                                                 if(player[0].bleeding<=0)
7467                                                 player[0].DoBlood(1,255);
7468                                                 }*/
7469
7470
7471                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7472                                                         int closest=-1;
7473                                                         float closestdist=-1;
7474                                                         float distance;
7475                                                         if(numplayers>1)
7476                                                                 for(i=1;i<numplayers;i++){
7477                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7478                                                                         if(closestdist==-1||distance<closestdist){
7479                                                                                 closestdist=distance;
7480                                                                                 closest=i;
7481                                                                         }
7482                                                                 }
7483                                                                 if(closestdist>0&&closest>=0){
7484                                                                         //player[closest]=player[numplayers-1];
7485                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7486                                                                         numplayers--;
7487                                                                 }
7488                                                                 drawmodetogglekeydown=1;
7489                                                 }
7490
7491                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7492                                                         int closest=-1;
7493                                                         float closestdist=-1;
7494                                                         float distance;
7495                                                         if(max_objects>1)
7496                                                                 for(i=1;i<max_objects;i++){
7497                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7498                                                                         if(closestdist==-1||distance<closestdist){
7499                                                                                 closestdist=distance;
7500                                                                                 closest=i;
7501                                                                         }
7502                                                                 }
7503                                                                 if(closestdist>0&&closest>=0){
7504                                                                         objects.position[closest].y-=500;
7505                                                                 }
7506                                                                 drawmodetogglekeydown=1;
7507                                                 }
7508
7509                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7510                                                         //drawmode++;
7511                                                         //if(drawmode>2)drawmode=0;
7512                                                         if(objects.numobjects<max_objects-1){
7513                                                                 XYZ boxcoords;
7514                                                                 boxcoords.x=player[0].coords.x;
7515                                                                 boxcoords.z=player[0].coords.z;
7516                                                                 boxcoords.y=player[0].coords.y-3;
7517                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7518                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7519                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7520                                                                 float temprotat,temprotat2;
7521                                                                 temprotat=editorrotation;
7522                                                                 temprotat2=editorrotation2;
7523                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7524                                                                 if(temprotat2<0)temprotat2=Random()%360;
7525
7526                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7527                                                                 if(editortype==treetrunktype)
7528                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7529                                                         }
7530
7531                                                         drawmodetogglekeydown=1;
7532                                                 }
7533
7534                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7535                                                         if(numplayers<maxplayers-1){
7536                                                                 player[numplayers].scale=.2*5*player[0].scale;
7537                                                                 player[numplayers].creature=rabbittype;
7538                                                                 player[numplayers].howactive=editoractive;
7539                                                                 player[numplayers].skeleton.id=numplayers;
7540                                                                 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);
7541
7542                                                                 //texsize=512*512*3/texdetail/texdetail;
7543                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7544                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7545
7546                                                                 k=abs(Random()%2)+1;
7547                                                                 if(k==0){
7548                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7549                                                                         player[numplayers].whichskin=0;
7550                                                                 }
7551                                                                 else if(k==1){
7552                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7553                                                                         player[numplayers].whichskin=1;
7554                                                                 }
7555                                                                 else {
7556                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7557                                                                         player[numplayers].whichskin=2;
7558                                                                 }
7559
7560                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7561                                                                 player[numplayers].power=1;
7562                                                                 player[numplayers].speedmult=1;
7563                                                                 player[numplayers].currentanimation=bounceidleanim;
7564                                                                 player[numplayers].targetanimation=bounceidleanim;
7565                                                                 player[numplayers].currentframe=0;
7566                                                                 player[numplayers].targetframe=1;
7567                                                                 player[numplayers].target=0;
7568                                                                 player[numplayers].bled=0;
7569                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
7570
7571                                                                 player[numplayers].targetrotation=player[0].targetrotation;
7572                                                                 player[numplayers].rotation=player[0].rotation;
7573
7574                                                                 player[numplayers].velocity=0;
7575                                                                 player[numplayers].coords=player[0].coords;
7576                                                                 player[numplayers].oldcoords=player[numplayers].coords;
7577                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
7578
7579                                                                 player[numplayers].id=numplayers;
7580                                                                 player[numplayers].skeleton.id=numplayers;
7581                                                                 player[numplayers].updatedelay=0;
7582                                                                 player[numplayers].normalsupdatedelay=0;
7583
7584                                                                 player[numplayers].aitype=passivetype;
7585                                                                 player[numplayers].aitarget=0;
7586
7587                                                                 if(player[0].creature==wolftype){
7588                                                                         headprop=player[0].proportionhead.x/1.1;
7589                                                                         bodyprop=player[0].proportionbody.x/1.1;
7590                                                                         armprop=player[0].proportionarms.x/1.1;
7591                                                                         legprop=player[0].proportionlegs.x/1.1;
7592                                                                 }
7593
7594                                                                 if(player[0].creature==rabbittype){
7595                                                                         headprop=player[0].proportionhead.x/1.2;
7596                                                                         bodyprop=player[0].proportionbody.x/1.05;
7597                                                                         armprop=player[0].proportionarms.x/1.00;
7598                                                                         legprop=player[0].proportionlegs.x/1.1;
7599                                                                 }
7600
7601                                                                 if(player[numplayers].creature==wolftype){
7602                                                                         player[numplayers].proportionhead=1.1*headprop;
7603                                                                         player[numplayers].proportionbody=1.1*bodyprop;
7604                                                                         player[numplayers].proportionarms=1.1*armprop;
7605                                                                         player[numplayers].proportionlegs=1.1*legprop;
7606                                                                 }
7607
7608                                                                 if(player[numplayers].creature==rabbittype){
7609                                                                         player[numplayers].proportionhead=1.2*headprop;
7610                                                                         player[numplayers].proportionbody=1.05*bodyprop;
7611                                                                         player[numplayers].proportionarms=1.00*armprop;
7612                                                                         player[numplayers].proportionlegs=1.1*legprop;
7613                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
7614                                                                 }
7615
7616                                                                 player[numplayers].headless=0;
7617                                                                 player[numplayers].onfire=0;
7618
7619                                                                 if(cellophane){
7620                                                                         player[numplayers].proportionhead.z=0;
7621                                                                         player[numplayers].proportionbody.z=0;
7622                                                                         player[numplayers].proportionarms.z=0;
7623                                                                         player[numplayers].proportionlegs.z=0;
7624                                                                 }
7625
7626                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
7627
7628                                                                 player[numplayers].damagetolerance=200;
7629
7630                                                                 player[numplayers].protectionhead=player[0].protectionhead;
7631                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
7632                                                                 player[numplayers].protectionlow=player[0].protectionlow;
7633                                                                 player[numplayers].armorhead=player[0].armorhead;
7634                                                                 player[numplayers].armorhigh=player[0].armorhigh;
7635                                                                 player[numplayers].armorlow=player[0].armorlow;
7636                                                                 player[numplayers].metalhead=player[0].metalhead;
7637                                                                 player[numplayers].metalhigh=player[0].metalhigh;
7638                                                                 player[numplayers].metallow=player[0].metallow;
7639
7640                                                                 player[numplayers].immobile=player[0].immobile;
7641
7642                                                                 player[numplayers].numclothes=player[0].numclothes;
7643                                                                 if(player[numplayers].numclothes)
7644                                                                         for(i=0;i<player[numplayers].numclothes;i++){
7645                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
7646                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
7647                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
7648                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
7649                                                                                 tintr=player[numplayers].clothestintr[i];
7650                                                                                 tintg=player[numplayers].clothestintg[i];
7651                                                                                 tintb=player[numplayers].clothestintb[i];
7652                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7653                                                                         }
7654                                                                         if(player[numplayers].numclothes){
7655                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
7656                                                                         }
7657
7658                                                                         player[numplayers].power=player[0].power;
7659                                                                         player[numplayers].speedmult=player[0].speedmult;
7660
7661                                                                         player[numplayers].damage=0;
7662                                                                         player[numplayers].permanentdamage=0;
7663                                                                         player[numplayers].superpermanentdamage=0;
7664                                                                         player[numplayers].deathbleeding=0;
7665                                                                         player[numplayers].bleeding=0;
7666                                                                         player[numplayers].numwaypoints=0;
7667                                                                         player[numplayers].waypoint=0;
7668                                                                         player[numplayers].jumppath=0;
7669                                                                         player[numplayers].weaponstuck=-1;
7670                                                                         player[numplayers].weaponactive=-1;
7671                                                                         player[numplayers].num_weapons=0;
7672                                                                         player[numplayers].bloodloss=0;
7673                                                                         player[numplayers].dead=0;
7674
7675                                                                         player[numplayers].loaded=1;
7676
7677                                                                         numplayers++;
7678                                                         }
7679                                                         drawmodetogglekeydown=1;
7680                                                 }
7681
7682                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
7683                                                         if(player[numplayers-1].numwaypoints<90){
7684                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
7685                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
7686                                                                 player[numplayers-1].numwaypoints++;
7687                                                         }
7688                                                         drawmodetogglekeydown=1;
7689                                                 }
7690
7691                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7692                                                         if(numpathpoints<30){
7693                                                                 bool connected,alreadyconnected;
7694                                                                 connected=0;
7695                                                                 if(numpathpoints>1)
7696                                                                         for(i=0;i<numpathpoints;i++){
7697                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
7698                                                                                         alreadyconnected=0;
7699                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
7700                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
7701                                                                                         }
7702                                                                                         if(!alreadyconnected){
7703                                                                                                 numpathpointconnect[pathpointselected]++;
7704                                                                                                 connected=1;
7705                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
7706                                                                                         }
7707                                                                                 }
7708                                                                         }
7709                                                                         if(!connected){
7710                                                                                 numpathpoints++;
7711                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
7712                                                                                 numpathpointconnect[numpathpoints-1]=0;
7713                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
7714                                                                                         numpathpointconnect[pathpointselected]++;
7715                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
7716                                                                                 }
7717                                                                                 pathpointselected=numpathpoints-1;
7718                                                                         }
7719                                                         }
7720                                                         drawmodetogglekeydown=1;
7721                                                 }
7722
7723                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
7724                                                         pathpointselected++;
7725                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
7726                                                         drawmodetogglekeydown=1;
7727                                                 }
7728                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
7729                                                         pathpointselected--;
7730                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
7731                                                         drawmodetogglekeydown=1;
7732                                                 }
7733                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
7734                                                         if(pathpointselected!=-1){
7735                                                                 numpathpoints--;
7736                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
7737                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
7738                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
7739                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
7740                                                                 }
7741                                                                 for(i=0;i<numpathpoints;i++){
7742                                                                         for(j=0;j<numpathpointconnect[i];j++){
7743                                                                                 if(pathpointconnect[i][j]==pathpointselected){
7744                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
7745                                                                                         numpathpointconnect[i]--;
7746                                                                                 }
7747                                                                                 if(pathpointconnect[i][j]==numpathpoints){
7748                                                                                         pathpointconnect[i][j]=pathpointselected;
7749                                                                                 }
7750                                                                         }
7751                                                                 }
7752                                                                 pathpointselected=numpathpoints-1;
7753                                                         }
7754                                                         drawmodetogglekeydown=1;
7755                                                 }
7756
7757                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7758                                                         editorenabled=1-editorenabled;
7759                                                         if(editorenabled){
7760                                                                 player[0].damagetolerance=100000;
7761                                                                 player[0].damage=0;
7762                                                                 player[0].superpermanentdamage=0;
7763                                                                 player[0].bloodloss=0;
7764                                                                 player[0].deathbleeding=0;
7765                                                         }
7766                                                         if(!editorenabled){
7767                                                                 player[0].damagetolerance=200;
7768                                                                 player[0].damage=0;
7769                                                                 player[0].permanentdamage=0;
7770                                                                 player[0].superpermanentdamage=0;
7771                                                                 player[0].bloodloss=0;
7772                                                                 player[0].deathbleeding=0;
7773                                                         }
7774                                                         drawmodetogglekeydown=1;
7775                                                 }
7776
7777                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7778                                                         editortype--;
7779                                                         if(editortype==treeleavestype||editortype==10)editortype--;
7780                                                         if(editortype<0)editortype=firetype;
7781                                                         drawmodetogglekeydown=1;
7782                                                 }
7783
7784                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7785                                                         editortype++;
7786                                                         if(editortype==treeleavestype||editortype==10)editortype++;
7787                                                         if(editortype>firetype)editortype=0;
7788                                                         drawmodetogglekeydown=1;
7789                                                 }
7790
7791                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7792                                                         editorrotation-=multiplier*100;
7793                                                         if(editorrotation<-.01)editorrotation=-.01;
7794                                                         drawmodetogglekeydown=1;
7795                                                 }
7796
7797                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7798                                                         editorrotation+=multiplier*100;
7799                                                         drawmodetogglekeydown=1;
7800                                                 }
7801
7802                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7803                                                         editorsize+=multiplier;
7804                                                         drawmodetogglekeydown=1;
7805                                                 }
7806
7807                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7808                                                         editorsize-=multiplier;
7809                                                         if(editorsize<.1)editorsize=.1;
7810                                                         drawmodetogglekeydown=1;
7811                                                 }
7812
7813
7814                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7815                                                         mapradius-=multiplier*10;
7816                                                 }
7817
7818                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7819                                                         mapradius+=multiplier*10;
7820                                                 }
7821                                                 /*
7822                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7823                                                 mapcenter.x+=multiplier*20;
7824                                                 }
7825
7826                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7827                                                 mapcenter.x-=multiplier*20;
7828                                                 }
7829
7830                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7831                                                 mapcenter.z+=multiplier*20;
7832                                                 }
7833
7834                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7835                                                 mapcenter.z-=multiplier*20;
7836                                                 }
7837                                                 */
7838                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7839                                                         editorrotation2+=multiplier*100;
7840                                                 }
7841
7842                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7843                                                         editorrotation2-=multiplier*100;
7844                                                         if(editorrotation2<-.01)editorrotation2=-.01;
7845                                                 }
7846                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7847                                                         int closest=-1;
7848                                                         float closestdist=-1;
7849                                                         float distance;
7850                                                         for(i=0;i<objects.numobjects;i++){
7851                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
7852                                                                 if(closestdist==-1||distance<closestdist){
7853                                                                         closestdist=distance;
7854                                                                         closest=i;
7855                                                                 }
7856                                                         }
7857                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
7858                                                         drawmodetogglekeydown=1;
7859                                                 }
7860
7861
7862                                                 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)){
7863                                                         drawmodetogglekeydown=0;
7864                                                 }
7865
7866                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
7867                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
7868                                                         player[0].RagDoll(0);
7869                                                         //player[0].spurt=1;
7870                                                         //player[0].DoDamage(1000);
7871
7872                                                         float gLoc[3];
7873                                                         float vel[3];
7874                                                         gLoc[0]=player[0].coords.x;
7875                                                         gLoc[1]=player[0].coords.y;
7876                                                         gLoc[2]=player[0].coords.z;
7877                                                         vel[0]=player[0].velocity.x;
7878                                                         vel[1]=player[0].velocity.y;
7879                                                         vel[2]=player[0].velocity.z;
7880                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
7881                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
7882                                                         OPENAL_SetVolume(channels[whooshsound], 128);
7883                                                         OPENAL_SetPaused(channels[whooshsound], false);
7884                                                         //OPENAL_SetPaused(channels[whooshsound], true);
7885
7886                                                         texturesizetogglekeydown=1;
7887                                                 }
7888
7889                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
7890
7891                                                         int closest=-1;
7892                                                         float closestdist=-1;
7893                                                         float distance;
7894                                                         for(i=0;i<objects.numobjects;i++){
7895                                                                 if(objects.type[i]==treeleavestype){
7896                                                                         objects.scale[i]*=.9;
7897                                                                 }
7898                                                         }
7899                                                         texturesizetogglekeydown=1;
7900                                                 }
7901
7902                                                 static XYZ relative;
7903                                                 static int randattack;
7904                                                 //Attack
7905                                                 static bool playerrealattackkeydown=0;
7906
7907                                                 if(!buttons[0])oldbutton=0;
7908                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
7909                                                 if(oldattackkey)player[0].attackkeydown=0;
7910                                                 if(oldattackkey)playerrealattackkeydown=0;
7911                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
7912                                                 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);
7913                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
7914                                                         for(k=0;k<numplayers;k++){
7915                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
7916                                                                         player[k].Reverse();
7917                                                         }
7918                                                 }
7919
7920                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
7921
7922                                                 for(k=0;k<numplayers;k++){
7923                                                         if(indialogue!=-1)player[k].attackkeydown=0;
7924                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
7925                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
7926                                                                 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)){
7927                                                                         player[k].jumppower-=2;
7928                                                                 }
7929                                                                 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)){
7930                                                                         for(i=0;i<numplayers;i++){
7931                                                                                 if(i==k)i++;
7932                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
7933                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
7934                                                                                                 player[k].targetanimation=dodgebackanim;
7935                                                                                                 player[k].target=0;
7936                                                                                                 player[k].targetframe=0;
7937                                                                                                 rotatetarget=player[i].coords-player[k].coords;
7938                                                                                                 Normalise(&rotatetarget);
7939                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
7940                                                                                                 player[k].targetrotation*=360/6.28;
7941                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
7942
7943                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
7944                                                                                         }
7945                                                                         }
7946                                                                         if(player[k].targetanimation!=dodgebackanim){
7947                                                                                 if(k==0)numflipped++;
7948                                                                                 player[k].targetanimation=backhandspringanim;
7949                                                                                 player[k].target=0;
7950                                                                                 player[k].targetframe=0;
7951                                                                                 player[k].targetrotation=-rotation+180;
7952                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
7953                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
7954                                                                                 player[k].rotation=player[k].targetrotation;
7955                                                                                 player[k].jumppower-=2;
7956                                                                         }
7957                                                                 }
7958                                                                 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())){
7959                                                                         player[k].hasvictim=0;
7960                                                                         if(numplayers>1)
7961                                                                                 for(i=0;i<numplayers;i++){
7962                                                                                         if(i==k)i++;
7963                                                                                         if(!player[k].hasvictim)
7964                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
7965                                                                                                         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){
7966                                                                                                                 player[k].victim=&player[i];
7967                                                                                                                 player[k].hasvictim=1;
7968                                                                                                                 if(player[k].aitype==playercontrolled){
7969                                                                                                                         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;
7970                                                                                                                         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;
7971                                                                                                                         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;
7972                                                                                                                         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;
7973                                                                                                                         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;
7974                                                                                                                         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;
7975                                                                                                                         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;
7976                                                                                                                         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;
7977                                                                                                                         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;
7978                                                                                                                         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;
7979                                                                                                                 }
7980                                                                                                                 else {
7981                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
7982                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
7983                                                                                                                                 else randattack=abs(Random()%5);
7984                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
7985                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
7986                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
7987                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
7988                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
7989                                                                                                                                 }
7990                                                                                                                                 if(player[k].weaponactive!=-1){
7991                                                                                                                                         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;
7992                                                                                                                                         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;
7993                                                                                                                                         //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;
7994                                                                                                                                         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;
7995                                                                                                                                         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;
7996                                                                                                                                         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;
7997                                                                                                                                         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;
7998                                                                                                                                         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;
7999                                                                                                                                 }
8000                                                                                                                         }
8001                                                                                                                 }
8002                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8003                                                                                                         }
8004                                                                                                         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)){
8005                                                                                                                 if(player[k].weaponactive==-1){
8006                                                                                                                         player[i].targetanimation=sneakattackedanim;
8007                                                                                                                         player[i].currentanimation=sneakattackedanim;
8008                                                                                                                         player[k].currentanimation=sneakattackanim;
8009                                                                                                                         player[k].targetanimation=sneakattackanim;
8010                                                                                                                         player[k].oldcoords=player[k].coords;
8011                                                                                                                         player[k].coords=player[i].coords;
8012                                                                                                                 }
8013                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8014                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8015                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8016                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8017                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8018                                                                                                                         player[i].oldcoords=player[i].coords;
8019                                                                                                                         player[i].coords=player[k].coords;
8020                                                                                                                 }
8021                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8022                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8023                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8024                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8025                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8026                                                                                                                         player[i].oldcoords=player[i].coords;
8027                                                                                                                         player[i].coords=player[k].coords;
8028                                                                                                                 }
8029                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8030                                                                                                                         player[k].victim=&player[i];
8031                                                                                                                         player[k].hasvictim=1;
8032                                                                                                                         player[i].targettilt2=0;
8033                                                                                                                         player[i].targetframe=1;
8034                                                                                                                         player[i].currentframe=0;
8035                                                                                                                         player[i].target=0;
8036                                                                                                                         player[i].velocity=0;
8037                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8038                                                                                                                         player[k].currentframe=player[i].currentframe;
8039                                                                                                                         player[k].targetframe=player[i].targetframe;
8040                                                                                                                         player[k].target=player[i].target;
8041                                                                                                                         player[k].velocity=0;
8042                                                                                                                         player[k].targetrotation=player[i].rotation;
8043                                                                                                                         player[k].rotation=player[i].rotation;
8044                                                                                                                         player[i].targetrotation=player[i].rotation;
8045                                                                                                                 }
8046                                                                                                         }
8047                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8048                                                                                                                 oldattackkey=1;
8049                                                                                                                 player[k].targetframe=0;
8050                                                                                                                 player[k].target=0;
8051                                                                                                                 //player[k].velocity=0;
8052
8053                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8054                                                                                                                 Normalise(&rotatetarget);
8055                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8056                                                                                                                 player[k].targetrotation*=360/6.28;
8057                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8058
8059                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8060
8061                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8062                                                                                                                 player[k].lastattack2=player[k].lastattack;
8063                                                                                                                 player[k].lastattack=player[k].targetanimation;
8064                                                                                                                 //player[k].targettilt2=0;
8065                                                                                                                 //slomo=1;
8066                                                                                                                 //slomodelay=.2;
8067                                                                                                         }
8068                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8069                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8070                                                                                                                 Normalise(&rotatetarget);
8071                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8072                                                                                                                 player[k].targetrotation*=360/6.28;
8073                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8074                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8075                                                                                                                 oldattackkey=1;
8076                                                                                                                 player[k].victim=&player[i];
8077                                                                                                                 player[k].hasvictim=1;
8078                                                                                                                 player[i].targetanimation=knifefollowedanim;
8079                                                                                                                 player[i].currentanimation=knifefollowedanim;
8080                                                                                                                 player[i].targettilt2=0;
8081                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8082                                                                                                                 player[i].targetframe=1;
8083                                                                                                                 player[i].currentframe=0;
8084                                                                                                                 player[i].target=0;
8085                                                                                                                 player[i].velocity=0;
8086                                                                                                                 player[k].currentanimation=knifefollowanim;
8087                                                                                                                 player[k].targetanimation=knifefollowanim;
8088                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8089                                                                                                                 player[k].currentframe=player[i].currentframe;
8090                                                                                                                 player[k].targetframe=player[i].targetframe;
8091                                                                                                                 player[k].target=player[i].target;
8092                                                                                                                 player[k].velocity=0;
8093                                                                                                                 player[k].oldcoords=player[k].coords;
8094                                                                                                                 player[i].coords=player[k].coords;
8095                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8096                                                                                                                 player[i].rotation=player[k].targetrotation;
8097                                                                                                                 player[k].rotation=player[k].targetrotation;
8098                                                                                                                 player[i].rotation=player[k].targetrotation;
8099                                                                                                         }
8100                                                                                                 }
8101                                                                                 }
8102                                                                                 bool hasstaff=0;
8103                                                                                 if(player[k].weaponactive!=-1){
8104                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8105                                                                                 }
8106                                                                                 if(numplayers>1)
8107                                                                                         for(i=0;i<numplayers;i++){
8108                                                                                                 if(i==k)i++;
8109                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
8110                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8111                                                                                                                 if(player[i].skeleton.free)
8112                                                                                                                         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)))){
8113                                                                                                                                 player[k].victim=&player[i];
8114                                                                                                                                 player[k].hasvictim=1;
8115                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8116                                                                                                                                         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;
8117                                                                                                                                         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;
8118                                                                                                                                         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;
8119                                                                                                                                 }
8120                                                                                                                                 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){
8121                                                                                                                                         player[k].targetanimation=killanim;
8122                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8123                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8124                                                                                                                                                         terrain.DeleteDecal(j);
8125                                                                                                                                                 }
8126                                                                                                                                         }
8127                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8128                                                                                                                                                 if(objects.model[l].type==decalstype)
8129                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8130                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8131                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8132                                                                                                                                                                 }
8133                                                                                                                                                         }
8134                                                                                                                                         }
8135                                                                                                                                 }
8136                                                                                                                                 if(!player[i].dead||musictype!=2)
8137                                                                                                                                         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)){
8138                                                                                                                                                 player[k].targetanimation=dropkickanim;
8139                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8140                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8141                                                                                                                                                                 terrain.DeleteDecal(j);
8142                                                                                                                                                         }
8143                                                                                                                                                 }
8144                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8145                                                                                                                                                         if(objects.model[l].type==decalstype)
8146                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8147                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8148                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8149                                                                                                                                                                         }
8150                                                                                                                                                                 }
8151                                                                                                                                                 }
8152                                                                                                                                         }
8153                                                                                                                         }
8154                                                                                                                         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)){
8155                                                                                                                                 oldattackkey=1;
8156                                                                                                                                 player[k].targetframe=0;
8157                                                                                                                                 player[k].target=0;
8158                                                                                                                                 //player[k].velocity=0;
8159
8160                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8161                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8162                                                                                                                                         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;
8163                                                                                                                                 }
8164                                                                                                                                 Normalise(&rotatetarget);
8165                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8166                                                                                                                                 player[k].targetrotation*=360/6.28;
8167                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8168
8169                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8170                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8171                                                                                                                                 }
8172
8173                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8174                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8175
8176                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8177                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8178                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8179
8180                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8181                                                                                                                                         player[k].targetrotation+=30;
8182                                                                                                                                 }
8183                                                                                                                                 //player[k].targettilt2=0;
8184                                                                                                                                 //slomo=1;
8185                                                                                                                                 //slomodelay=.2;
8186                                                                                                                         }
8187                                                                                                 }
8188                                                                                         }
8189                                                                                         if(!player[k].hasvictim){
8190                                                                                                 for(i=0;i<numplayers;i++){
8191                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8192                                                                                                                 player[k].victim=&player[i];
8193                                                                                                                 player[k].hasvictim=1;
8194                                                                                                         }
8195                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8196                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8197                                                                                                                         player[k].victim=&player[i];
8198                                                                                                                 }
8199                                                                                                 }
8200                                                                                         }
8201                                                                                         if(player[k].aitype==playercontrolled)
8202                                                                                                 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)){
8203                                                                                                         oldattackkey=1;
8204                                                                                                         player[k].targetanimation=rabbitkickanim;
8205                                                                                                         player[k].targetframe=0;
8206                                                                                                         player[k].target=0;
8207                                                                                                 }
8208                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8209                                                                                                         numattacks++;
8210                                                                                                         bool armedstaff=0;
8211                                                                                                         if(player[k].weaponactive!=-1){
8212                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8213                                                                                                         }
8214                                                                                                         bool armedsword=0;
8215                                                                                                         if(player[k].weaponactive!=-1){
8216                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8217                                                                                                         }
8218                                                                                                         bool armedknife=0;
8219                                                                                                         if(player[k].weaponactive!=-1){
8220                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8221                                                                                                         }
8222                                                                                                         if(armedstaff)numstaffattack++;
8223                                                                                                         else if(armedsword)numswordattack++;
8224                                                                                                         else if(armedknife)numknifeattack++;
8225                                                                                                         else numunarmedattack++;
8226                                                                                                 }
8227                                                                 }
8228                                                         }
8229                                                 }
8230
8231                                                 //Collisions
8232                                                 static float collisionradius;
8233                                                 if(numplayers>1)
8234                                                         for(k=0;k<numplayers;k++){
8235                                                                 for(i=k;i<numplayers;i++){
8236                                                                         if(i==k)i++;
8237                                                                         if(i<numplayers)
8238                                                                                 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))
8239                                                                                         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))
8240                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8241                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8242                                                                                                                 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)
8243                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8244                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8245                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8246                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8247                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8248                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8249                                                                                                                                                                         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)){
8250                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8251                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8252                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8253                                                                                                                                                                                 }
8254                                                                                                                                                                         }
8255
8256                                                                                                                                                                         tempcoords1=player[i].coords;
8257                                                                                                                                                                         tempcoords2=player[k].coords;
8258                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8259                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8260                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8261                                                                                                                                                                         if(player[0].hasvictim)
8262                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8263                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
8264                                                                                                                                                                                 if(k==0)
8265                                                                                                                                                                                         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)){
8266                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8267                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8268                                                                                                                                                                                                 player[i].skeleton.free=0;
8269                                                                                                                                                                                                 player[i].rotation=0;
8270                                                                                                                                                                                                 player[i].RagDoll(0);
8271                                                                                                                                                                                                 player[i].DoDamage(20);
8272                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8273                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8274                                                                                                                                                                                                 player[k].lastcollide=1;
8275                                                                                                                                                                                         }
8276                                                                                                                                                                                         if(i==0)
8277                                                                                                                                                                                                 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)){
8278                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8279                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8280                                                                                                                                                                                                         player[k].skeleton.free=0;
8281                                                                                                                                                                                                         player[k].rotation=0;
8282                                                                                                                                                                                                         player[k].RagDoll(0);
8283                                                                                                                                                                                                         player[k].DoDamage(20);
8284                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8285                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8286                                                                                                                                                                                                         player[i].lastcollide=1;
8287                                                                                                                                                                                                 }
8288
8289                                                                                                                                                                                                 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)){
8290                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8291                                                                                                                                                                                                         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))
8292                                                                                                                                                                                                                 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))){
8293                                                                                                                                                                                                                         //If hit by body
8294                                                                                                                                                                                                                         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)){
8295                                                                                                                                                                                                                                 static float gLoc[3];
8296                                                                                                                                                                                                                                 static float vel[3];
8297                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8298                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8299                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8300                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8301                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8302                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8303                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8304                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
8305                                                                                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8306                                                                                                                                                                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 256);
8307                                                                                                                                                                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
8308                                                                                                                                                                                                                                 }
8309                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8310                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8311
8312                                                                                                                                                                                                                                 player[i].RagDoll(0);
8313                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8314                                                                                                                                                                                                                                         bonus=aimbonus;
8315                                                                                                                                                                                                                                         bonustime=0;
8316                                                                                                                                                                                                                                         bonusvalue=150;
8317                                                                                                                                                                                                                                 }
8318                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8319                                                                                                                                                                                                                                 player[k].RagDoll(0);
8320                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8321                                                                                                                                                                                                                                         bonus=aimbonus;
8322                                                                                                                                                                                                                                         bonustime=0;
8323                                                                                                                                                                                                                                         bonusvalue=150;
8324                                                                                                                                                                                                                                 }
8325                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8326
8327                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8328                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8329                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8330                                                                                                                                                                                                                                 }
8331                                                                                                                                                                                                                                 //}
8332                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8333                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8334                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8335                                                                                                                                                                                                                                 }
8336                                                                                                                                                                                                                                 //}
8337
8338                                                                                                                                                                                                                         }
8339                                                                                                                                                                                                                 }
8340                                                                                                                                                                                                                 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)){
8341                                                                                                                                                                                                                         //If bumped
8342                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8343                                                                                                                                                                                                                                 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)){
8344                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8345                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8346                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8347                                                                                                                                                                                                                                         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);
8348                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8349                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8350                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8351                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8352                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8353                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8354                                                                                                                                                                                                                                                                 player[k].target=0;
8355                                                                                                                                                                                                                                                         }
8356                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8357                                                                                                                                                                                                                                                         {
8358                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8359                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8360                                                                                                                                                                                                                                                                 player[k].target=0;
8361                                                                                                                                                                                                                                                         }
8362                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8363                                                                                                                                                                                                                                                 }
8364                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8365                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8366                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8367                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8368                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8369                                                                                                                                                                                                                                                                         player[i].target=0;
8370                                                                                                                                                                                                                                                                 }
8371                                                                                                                                                                                                                                                                 else
8372                                                                                                                                                                                                                                                                 {
8373                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8374                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8375                                                                                                                                                                                                                                                                         player[i].target=0;
8376                                                                                                                                                                                                                                                                 }
8377                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8378                                                                                                                                                                                                                                                         }
8379                                                                                                                                                                                                                                 }
8380                                                                                                                                                                                                                                 if(hostile){
8381                                                                                                                                                                                                                                         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){
8382                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8383                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8384                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8385                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8386                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8387                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8388                                                                                                                                                                                                                                                 player[k].lastcollide=1;
8389                                                                                                                                                                                                                                                 if(k==0){
8390                                                                                                                                                                                                                                                         bonus=AboveBonus;
8391                                                                                                                                                                                                                                                         bonustime=0;
8392                                                                                                                                                                                                                                                         bonusvalue=50;
8393                                                                                                                                                                                                                                                 }
8394                                                                                                                                                                                                                                         }
8395                                                                                                                                                                                                                                         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){
8396                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8397                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8398                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8399                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8400                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8401                                                                                                                                                                                                                                                 player[k].RagDoll(0);
8402                                                                                                                                                                                                                                                 player[i].lastcollide=1;
8403                                                                                                                                                                                                                                                 if(i==0){
8404                                                                                                                                                                                                                                                         bonus=AboveBonus;
8405                                                                                                                                                                                                                                                         bonustime=0;
8406                                                                                                                                                                                                                                                         bonusvalue=50;
8407                                                                                                                                                                                                                                                 }
8408                                                                                                                                                                                                                                         }
8409                                                                                                                                                                                                                                 }
8410                                                                                                                                                                                                                         }
8411                                                                                                                                                                                                                 }
8412                                                                                                                                                                                                 }
8413                                                                                                                                                                                                 player[i].CheckKick();
8414                                                                                                                                                                                                 player[k].CheckKick();
8415                                                                                                                                                                         }
8416                                                                                                                                                                 }
8417                                                                 }
8418                                                         }
8419
8420                                                         for(k=0;k<numplayers;k++){
8421                                                                 for(i=k;i<numplayers;i++){
8422                                                                         if(i==k)i++;
8423                                                                         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))){
8424                                                                                 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)){
8425                                                                                         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)){
8426                                                                                                 player[i].victim=&player[k];
8427                                                                                                 player[i].targetanimation=jumpreversedanim;
8428                                                                                                 player[i].currentanimation=jumpreversedanim;
8429                                                                                                 player[k].currentanimation=jumpreversalanim;
8430                                                                                                 player[k].targetanimation=jumpreversalanim;
8431                                                                                                 player[i].targettilt2=0;
8432                                                                                                 player[i].currentframe=0;
8433                                                                                                 player[i].targetframe=1;
8434                                                                                                 player[k].currentframe=0;
8435                                                                                                 player[k].targetframe=1;
8436                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8437                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8438                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8439                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8440                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8441                                                                                                         player[k].currentframe=1;
8442                                                                                                         player[k].targetframe=2;
8443                                                                                                         player[i].currentframe=1;
8444                                                                                                         player[i].targetframe=2;
8445                                                                                                 }
8446                                                                                                 player[k].targettilt2=0;
8447                                                                                                 player[i].target=0;
8448                                                                                                 player[i].velocity=0;
8449                                                                                                 player[k].velocity=0;
8450                                                                                                 player[k].oldcoords=player[k].coords;
8451                                                                                                 player[i].coords=player[k].coords;
8452                                                                                                 player[k].targetrotation=player[i].targetrotation;
8453                                                                                                 player[k].rotation=player[i].targetrotation;
8454                                                                                                 player[k].victim=&player[i];
8455                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8456                                                                                         }
8457                                                                                         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)){
8458                                                                                                 player[k].victim=&player[i];
8459                                                                                                 player[k].targetanimation=jumpreversedanim;
8460                                                                                                 player[k].currentanimation=jumpreversedanim;
8461                                                                                                 player[i].currentanimation=jumpreversalanim;
8462                                                                                                 player[i].targetanimation=jumpreversalanim;
8463                                                                                                 player[k].targettilt2=0;
8464                                                                                                 player[i].targettilt2=0;
8465                                                                                                 player[k].currentframe=0;
8466                                                                                                 player[k].targetframe=1;
8467                                                                                                 player[i].currentframe=0;
8468                                                                                                 player[i].targetframe=1;
8469                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8470                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8471                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8472                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8473                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8474                                                                                                         player[k].currentframe=1;
8475                                                                                                         player[k].targetframe=2;
8476                                                                                                         player[i].currentframe=1;
8477                                                                                                         player[i].targetframe=2;
8478                                                                                                 }
8479                                                                                                 player[k].target=0;
8480                                                                                                 player[k].velocity=0;
8481                                                                                                 player[i].velocity=0;
8482                                                                                                 player[i].oldcoords=player[i].coords;
8483                                                                                                 player[k].coords=player[i].coords;
8484                                                                                                 player[i].targetrotation=player[k].targetrotation;
8485                                                                                                 player[i].rotation=player[k].targetrotation;
8486                                                                                                 player[i].victim=&player[k];
8487                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8488                                                                                         }
8489                                                                                 }
8490                                                                         }
8491                                                                 }
8492                                                         }
8493
8494                                                         for(k=0;k<numplayers;k++)
8495                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8496
8497
8498                                                         //pile
8499                                                         /*
8500                                                         XYZ tempdiff;
8501                                                         XYZ tempoldpos;
8502                                                         XYZ temp1,temp2;
8503                                                         bool isgood;
8504                                                         static float checkdelay;
8505                                                         checkdelay-=multiplier;
8506                                                         int m;
8507                                                         static bool checkedcoll[maxplayers][maxplayers];
8508                                                         static bool above[maxplayers];
8509
8510                                                         for(i=0;i<maxplayers;i++){
8511                                                         for(j=0;j<maxplayers;j++){
8512                                                         checkedcoll[i][j]=0;
8513                                                         }
8514                                                         }
8515
8516                                                         if(numplayers>1&&checkdelay<=0){
8517                                                         checkdelay=.015;
8518                                                         for(k=0;k<numplayers;k++){
8519                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8520
8521                                                         for(i=k;i<numplayers;i++){
8522                                                         if(i==k)i++;
8523                                                         if(i<numplayers)
8524                                                         if(!checkedcoll[i][k]){
8525                                                         checkedcoll[i][k]=1;
8526                                                         checkedcoll[k][i]=1;
8527                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8528                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8529                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8530                                                         if(player[i].coords.y>player[k].coords.y-3)
8531                                                         if(player[i].coords.y<player[k].coords.y+3)
8532                                                         if(player[i].coords.x>player[k].coords.x-3)
8533                                                         if(player[i].coords.x<player[k].coords.x+3)
8534                                                         if(player[i].coords.z>player[k].coords.z-3)
8535                                                         if(player[i].coords.z<player[k].coords.z+3)
8536                                                         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)){
8537                                                         int stuck,moving;
8538                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8539                                                         stuck=i;
8540                                                         moving=k;
8541                                                         }
8542                                                         else
8543                                                         {
8544                                                         moving=i;
8545                                                         stuck=k;
8546                                                         }
8547                                                         isgood=1;
8548
8549                                                         if(isgood){
8550                                                         above[moving]=stuck;
8551                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8552                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8553                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8554                                                         {
8555                                                         player[moving].skeleton.joints[l].position.y+=.003;
8556                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8557
8558                                                         }
8559                                                         }
8560                                                         }
8561                                                         }
8562                                                         }
8563                                                         }
8564                                                         }
8565                                                         }
8566                                                         }
8567
8568                                                         */
8569
8570                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
8571                                                                 texturesizetogglekeydown=0;
8572                                                         }
8573
8574                                                         for(k=0;k<numplayers;k++){
8575                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8576                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8577                                                                                 player[k].DoDamage(1000);
8578                                                                         }
8579                                                                 }
8580                                                         }
8581
8582                                                         static bool respawnkeydown;
8583                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
8584                                                                 targetlevel=whichlevel;
8585                                                                 loading=1;
8586                                                                 leveltime=5;
8587                                                         }
8588                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
8589                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
8590
8591
8592
8593
8594                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
8595                                                                 targetlevel++;
8596                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
8597                                                                 loading=1;
8598                                                                 leveltime=5;
8599                                                                 slomotogglekeydown=1;
8600                                                         }
8601
8602                                                         /*
8603                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
8604                                                         //Respawn
8605                                                         OPENAL_SetPaused(channels[whooshsound], true);
8606                                                         changedelay=0;
8607                                                         for(k=0;k<numplayers;k++){
8608                                                         player[k].dead=0;
8609                                                         player[k].damage=0;
8610                                                         player[k].permanentdamage=0;
8611                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
8612                                                         player[k].aitype=passivetype;
8613                                                         }
8614                                                         player[0].aitype=playercontrolled;
8615                                                         }
8616                                                         */
8617
8618                                                         static bool movekey;
8619                                                         static bool connected;
8620                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
8621                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
8622                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
8623                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
8624                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
8625                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
8626
8627                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
8628
8629                 for(int i=0;i<numplayers;i++){
8630                                                                 if(!player[i].skeleton.free){
8631                                                                         oldtargetrotation=player[i].targetrotation;
8632                                                                         if(i==0&&indialogue==-1){
8633                                                                                 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){
8634                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
8635                                                                                         if(cameramode)player[0].targetrotation=0;
8636                                                                                 }
8637
8638                                                                                 facing=0;
8639                                                                                 facing.z=-1;
8640
8641                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
8642                                                                                 if(cameramode){facing=flatfacing;}
8643                                                                                 else{
8644                                                                                         facing=DoRotation(facing,-rotation2,0,0);
8645                                                                                         facing=DoRotation(facing,0,0-rotation,0);
8646                                                                                 }
8647
8648                                                                                 player[0].lookrotation=-rotation;
8649
8650                                                                                 player[i].targetheadrotation=rotation;
8651                                                                                 player[i].targetheadrotation2=rotation2;
8652                                                                         }
8653                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
8654                                                                                 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){
8655                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
8656                                                                                 }
8657
8658                                                                                 facing=0;
8659                                                                                 facing.z=-1;
8660
8661                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
8662
8663                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
8664                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
8665
8666                                                                                 player[i].targetheadrotation=player[i].lookrotation;
8667                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;
8668                                                                         }
8669                                                                         if(indialogue!=-1){
8670                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
8671                                                                                 Normalise(&rotatetarget);
8672                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
8673                                                                                 player[i].targetheadrotation*=360/6.28;
8674                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
8675
8676                                                                                 player[i].targetheadrotation*=-1;
8677                                                                                 player[i].targetheadrotation+=180;
8678                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
8679                                                                         }
8680
8681                                                                         bool pause;
8682
8683                                                                         if(leveltime<.5)
8684                                                                                 numenvsounds=0;
8685
8686                                                                         player[i].avoidsomething=0;
8687
8688                                                                         for(j=0;j<objects.numobjects;j++){
8689                                                                                 if(objects.onfire[j]){
8690                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
8691                                                                                         {
8692                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
8693                                                                                                         player[i].collided=0;
8694                                                                                                         player[i].avoidcollided=1;
8695                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
8696                                                                                                                 player[i].avoidwhere=objects.position[j];
8697                                                                                                 }
8698                                                                                         }
8699                                                                                 }
8700                                                                         }
8701
8702                                                                         //Add avoidwhere to players
8703
8704                                                                         for(j=0;j<numplayers;j++){
8705                                                                                 if(player[j].onfire){
8706                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
8707                                                                                         {
8708                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
8709                                                                                                         player[i].collided=0;
8710                                                                                                         player[i].avoidcollided=1;
8711                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
8712                                                                                                                 player[i].avoidwhere=objects.position[j];
8713                                                                                                 }
8714                                                                                         }
8715                                                                                 }
8716                                                                         }
8717
8718                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
8719                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
8720                                                                                 player[i].jumpclimb=0;
8721                                                                                 //AI
8722                                                                                 if(editorenabled)player[i].stunned=1;
8723
8724                                                                                 player[i].pause=0;
8725                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
8726                                                                                 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;
8727
8728                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
8729                                                                                 player[i].forwardkeydown=0;
8730                                                                                 player[i].leftkeydown=0;
8731                                                                                 player[i].backkeydown=0;
8732                                                                                 player[i].rightkeydown=0;
8733                                                                                 player[i].crouchkeydown=0;
8734                                                                                 player[i].attackkeydown=0;
8735                                                                                 player[i].jumpkeydown=0;
8736                                                                                 player[i].throwkeydown=0;
8737                                                                                 }*/
8738
8739                                                                                 if(player[i].aitype==pathfindtype){
8740                                                                                         if(player[i].finalpathfindpoint==-1){
8741                                                                                                 float closestdistance;
8742                                                                                                 float tempdist;
8743                                                                                                 int closest;
8744                                                                                                 XYZ colpoint;
8745                                                                                                 closest=-1;
8746                                                                                                 closestdistance=-1;
8747                                                                                                 for(j=0;j<numpathpoints;j++){
8748                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
8749                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
8750                                                                                                                 closest=j;
8751                                                                                                                 player[i].finaltarget=pathpoint[j];
8752                                                                                                         }
8753                                                                                                 }
8754                                                                                                 player[i].finalpathfindpoint=closest;
8755                                                                                                 for(j=0;j<numpathpoints;j++){
8756                                                                                                         if(numpathpointconnect[j])
8757                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8758                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
8759                                                                                                                         if(tempdist*tempdist<closestdistance){
8760                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
8761                                                                                                                                         closestdistance=tempdist*tempdist;
8762                                                                                                                                         closest=j;
8763                                                                                                                                         player[i].finaltarget=colpoint;
8764                                                                                                                                 }
8765                                                                                                                         }
8766                                                                                                                 }
8767                                                                                                 }
8768                                                                                                 player[i].finalpathfindpoint=closest;
8769
8770                                                                                         }
8771                                                                                         if(player[i].targetpathfindpoint==-1){
8772                                                                                                 float closestdistance;
8773                                                                                                 float tempdist;
8774                                                                                                 int closest;
8775                                                                                                 XYZ colpoint;
8776                                                                                                 closest=-1;
8777                                                                                                 closestdistance=-1;
8778                                                                                                 if(player[i].lastpathfindpoint==-1){
8779                                                                                                         for(j=0;j<numpathpoints;j++){
8780                                                                                                                 if(j!=player[i].lastpathfindpoint)
8781                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
8782                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
8783                                                                                                                                 closest=j;
8784                                                                                                                         }
8785                                                                                                         }
8786                                                                                                         player[i].targetpathfindpoint=closest;
8787                                                                                                         for(j=0;j<numpathpoints;j++){
8788                                                                                                                 if(j!=player[i].lastpathfindpoint)
8789                                                                                                                         if(numpathpointconnect[j])
8790                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8791                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
8792                                                                                                                                         if(tempdist*tempdist<closestdistance){
8793                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
8794                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
8795                                                                                                                                                         closestdistance=tempdist*tempdist;
8796                                                                                                                                                         closest=j;
8797                                                                                                                                                         //}
8798                                                                                                                                                 }
8799                                                                                                                                         }
8800                                                                                                                                 }
8801                                                                                                         }
8802                                                                                                         player[i].targetpathfindpoint=closest;
8803                                                                                                 }
8804                                                                                                 else
8805                                                                                                 {
8806                                                                                                         for(j=0;j<numpathpoints;j++){
8807                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
8808                                                                                                                 {
8809                                                                                                                         connected=0;
8810                                                                                                                         if(numpathpointconnect[j])
8811                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8812                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
8813                                                                                                                                 }
8814                                                                                                                                 if(!connected)
8815                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
8816                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
8817                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
8818                                                                                                                                                 }
8819                                                                                                                                                 if(connected){
8820                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
8821                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
8822                                                                                                                                                                 closestdistance=tempdist;
8823                                                                                                                                                                 closest=j;
8824                                                                                                                                                         }
8825                                                                                                                                                 }
8826                                                                                                                 }
8827                                                                                                         }
8828                                                                                                         player[i].targetpathfindpoint=closest;
8829                                                                                                 }
8830                                                                                         }
8831                                                                                         player[i].losupdatedelay-=multiplier;
8832
8833                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
8834                                                                                         Normalise(&rotatetarget);
8835                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
8836                                                                                         player[i].targetrotation*=360/6.28;
8837                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
8838                                                                                         player[i].lookrotation=player[i].targetrotation;
8839                                                                                         //player[i].aiupdatedelay=.05;
8840
8841                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
8842                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
8843                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
8844                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
8845                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
8846                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
8847                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
8848                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
8849                                                                                                 player[i].targetpathfindpoint=-1;
8850                                                                                         }
8851                                                                                         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){
8852                                                                                                 player[i].aitype=passivetype;
8853                                                                                         }
8854
8855                                                                                         player[i].forwardkeydown=1;
8856                                                                                         player[i].leftkeydown=0;
8857                                                                                         player[i].backkeydown=0;
8858                                                                                         player[i].rightkeydown=0;
8859                                                                                         player[i].crouchkeydown=0;
8860                                                                                         player[i].attackkeydown=0;
8861                                                                                         player[i].throwkeydown=0;
8862
8863                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
8864
8865                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
8866                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
8867
8868                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
8869                                                                                                 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))
8870                                                                                                         player[i].aitype=attacktypecutoff;
8871                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
8872                                                                                                         player[i].aitype=attacktypecutoff;
8873
8874                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
8875                                                                                                         player[i].losupdatedelay=.2;
8876                                                                                                         for(j=0;j<numplayers;j++){
8877                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
8878                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
8879                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
8880                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
8881                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
8882                                                                                                                                                         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)){
8883                                                                                                                                                                 player[i].aitype=searchtype;
8884                                                                                                                                                                 player[i].lastchecktime=12;
8885                                                                                                                                                                 player[i].lastseen=player[j].coords;
8886                                                                                                                                                                 player[i].lastseentime=12;
8887                                                                                                                                                         }
8888                                                                                                                 }
8889                                                                                                         }
8890                                                                                                 }
8891                                                                                         }
8892                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
8893                                                                                                 if(player[i].creature!=wolftype){
8894                                                                                                         player[i].stunned=.6;
8895                                                                                                         player[i].surprised=.6;
8896                                                                                                 }
8897                                                                                         }
8898                                                                                 }
8899
8900                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
8901                                                                                         player[i].howactive=typeactive;
8902                                                                                 }
8903
8904                                                                                 if(player[i].aitype==passivetype){
8905                                                                                         player[i].aiupdatedelay-=multiplier;
8906                                                                                         player[i].losupdatedelay-=multiplier;
8907                                                                                         player[i].lastseentime+=multiplier;
8908                                                                                         player[i].pausetime-=multiplier;
8909                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
8910
8911                                                                                         if(player[i].aiupdatedelay<0){
8912                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
8913                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
8914                                                                                                         Normalise(&rotatetarget);
8915                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
8916                                                                                                         player[i].targetrotation*=360/6.28;
8917                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
8918                                                                                                         player[i].lookrotation=player[i].targetrotation;
8919                                                                                                         player[i].aiupdatedelay=.05;
8920
8921                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
8922                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
8923                                                                                                                 player[i].waypoint++;
8924                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
8925
8926                                                                                                         }
8927                                                                                                 }
8928
8929                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
8930                                                                                                 else player[i].forwardkeydown=0;
8931                                                                                                 player[i].leftkeydown=0;
8932                                                                                                 player[i].backkeydown=0;
8933                                                                                                 player[i].rightkeydown=0;
8934                                                                                                 player[i].crouchkeydown=0;
8935                                                                                                 player[i].attackkeydown=0;
8936                                                                                                 player[i].throwkeydown=0;
8937
8938                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
8939                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
8940                                                                                                         else{
8941                                                                                                                 XYZ leftpos,rightpos;
8942                                                                                                                 float leftdist,rightdist;
8943                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
8944                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
8945                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
8946                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
8947                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
8948                                                                                                                 else player[i].targetrotation-=90;
8949                                                                                                         }
8950                                                                                                 }
8951                                                                                         }
8952                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
8953                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
8954
8955
8956                                                                                         if(!editorenabled){
8957                                                                                                 if(player[i].howactive<typesleeping)
8958                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
8959                                                                                                                 for(j=0;j<numenvsounds;j++){
8960                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
8961                                                                                                                                 player[i].aitype=attacktypecutoff;
8962                                                                                                                         }
8963                                                                                                                 }
8964
8965                                                                                                                 if(player[i].howactive==typesleeping)
8966                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
8967                                                                                                                                 for(j=0;j<numenvsounds;j++){
8968                                                                                                                                         if(envsoundvol[j]>14)
8969                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
8970                                                                                                                                                         player[i].aitype=attacktypecutoff;
8971                                                                                                                                                 }
8972                                                                                                                                 }
8973
8974                                                                                                                                 if(player[i].aitype!=passivetype){
8975                                                                                                                                         if(player[i].howactive==typesleeping){
8976                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
8977                                                                                                                                                 player[i].targetframe=0;
8978                                                                                                                                                 player[i].target=0;
8979                                                                                                                                         }
8980
8981                                                                                                                                         player[i].howactive=typeactive;
8982                                                                                                                                 }
8983                                                                                         }
8984
8985                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
8986                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
8987                                                                                                         player[i].aitype=attacktypecutoff;
8988                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
8989                                                                                                         player[i].aitype=attacktypecutoff;
8990
8991                                                                                                 if(player[i].creature==wolftype){
8992                                                                                                         XYZ windsmell;
8993                                                                                                         float smelldistance;
8994                                                                                                         smelldistance=50;
8995                                                                                                         for(j=0;j<numplayers;j++){
8996                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
8997                                                                                                                         if(j==0&&player[j].num_weapons>0){
8998                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
8999                                                                                                                                 if(player[j].num_weapons==2)
9000                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9001                                                                                                                         }
9002                                                                                                                         if(j!=0){
9003                                                                                                                                 smelldistance=100;
9004                                                                                                                         }
9005                                                                                                                         windsmell=windvector;
9006                                                                                                                         Normalise(&windsmell);
9007                                                                                                                         windsmell=windsmell*2+player[j].coords;
9008                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9009                                                                                                                                 player[i].aitype=attacktypecutoff;
9010                                                                                                                 }
9011                                                                                                         }
9012                                                                                                 }
9013
9014                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9015                                                                                                         player[i].losupdatedelay=.2;
9016                                                                                                         for(j=0;j<numplayers;j++){
9017                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9018                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9019                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9020                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9021                                                                                                                                                 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)){
9022                                                                                                                                                         player[i].lastseentime-=.2;
9023                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9024                                                                                                                                                         else player[i].lastseentime-=.6;
9025                                                                                                                                                 }
9026                                                                                                                                                 if(player[i].lastseentime<=0){
9027                                                                                                                                                         player[i].aitype=searchtype;
9028                                                                                                                                                         player[i].lastchecktime=12;
9029                                                                                                                                                         player[i].lastseen=player[j].coords;
9030                                                                                                                                                         player[i].lastseentime=12;
9031                                                                                                                                                 }
9032                                                                                                                 }
9033                                                                                                         }
9034                                                                                                 }
9035                                                                                         }
9036                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9037                                                                                                 if(player[i].creature!=wolftype){
9038                                                                                                         player[i].stunned=.6;
9039                                                                                                         player[i].surprised=.6;
9040                                                                                                 }
9041                                                                                                 if(player[i].creature==wolftype){
9042                                                                                                         player[i].stunned=.47;
9043                                                                                                         player[i].surprised=.47;
9044                                                                                                 }
9045                                                                                                 numseen++;
9046                                                                                         }
9047                                                                                 }
9048
9049                                                                                 if(player[i].aitype==searchtype){
9050                                                                                         player[i].aiupdatedelay-=multiplier;
9051                                                                                         player[i].losupdatedelay-=multiplier;
9052                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9053                                                                                         player[i].lastchecktime-=multiplier;
9054
9055                                                                                         if(player[i].isRun()&&!player[i].onground){
9056                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9057                                                                                                         test2=player[i].coords+player[i].facing;
9058                                                                                                         test2.y+=5;
9059                                                                                                         test=player[i].coords+player[i].facing;
9060                                                                                                         test.y-=10;
9061                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9062                                                                                                         if(j==-1)j=checkcollide(test2,test);
9063                                                                                                         if(j==-1){
9064                                                                                                                 player[i].velocity=0;
9065                                                                                                                 player[i].targetanimation=player[i].getStop();
9066                                                                                                                 player[i].targetframe=0;
9067                                                                                                                 player[i].target=0;
9068                                                                                                                 player[i].targetrotation+=180;
9069                                                                                                                 player[i].stunned=.5;
9070                                                                                                                 //player[i].aitype=passivetype;
9071                                                                                                                 player[i].aitype=pathfindtype;
9072                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9073                                                                                                                 player[i].finalpathfindpoint=-1;
9074                                                                                                                 player[i].targetpathfindpoint=-1;
9075                                                                                                                 player[i].lastpathfindpoint=-1;
9076                                                                                                                 player[i].lastpathfindpoint2=-1;
9077                                                                                                                 player[i].lastpathfindpoint3=-1;
9078                                                                                                                 player[i].lastpathfindpoint4=-1;
9079                                                                                                         }
9080                                                                                                         else player[i].laststanding=j;
9081                                                                                                 }
9082                                                                                         }
9083                                                                                         if(player[i].aiupdatedelay<0){
9084                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9085                                                                                                 Normalise(&rotatetarget);
9086                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9087                                                                                                 player[i].targetrotation*=360/6.28;
9088                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9089                                                                                                 player[i].lookrotation=player[i].targetrotation;
9090                                                                                                 player[i].aiupdatedelay=.05;
9091                                                                                                 player[i].forwardkeydown=1;
9092
9093                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9094                                                                                                         player[i].forwardkeydown=0;
9095                                                                                                         player[i].aiupdatedelay=1;
9096                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9097                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9098                                                                                                         player[i].lastchecktime=3;
9099                                                                                                 }
9100
9101                                                                                                 player[i].leftkeydown=0;
9102                                                                                                 player[i].backkeydown=0;
9103                                                                                                 player[i].rightkeydown=0;
9104                                                                                                 player[i].crouchkeydown=0;
9105                                                                                                 player[i].attackkeydown=0;
9106                                                                                                 player[i].throwkeydown=0;
9107
9108                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9109                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9110                                                                                                         else{
9111                                                                                                                 XYZ leftpos,rightpos;
9112                                                                                                                 float leftdist,rightdist;
9113                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9114                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9115                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9116                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9117                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9118                                                                                                                 else player[i].targetrotation-=90;
9119                                                                                                         }
9120                                                                                                 }
9121                                                                                         }
9122                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9123                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9124
9125                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9126                                                                                                 for(j=0;j<numenvsounds;j++){
9127                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9128                                                                                                                 player[i].aitype=attacktypecutoff;
9129                                                                                                         }
9130                                                                                                 }
9131
9132                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9133                                                                                                         player[i].losupdatedelay=.2;
9134                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9135                                                                                                         {player[i].aitype=attacktypecutoff;
9136                                                                                                         player[i].lastseentime=1;}
9137                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9138                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9139                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9140                                                                                                                                 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)){
9141                                                                                                                                         player[i].aitype=attacktypecutoff;
9142                                                                                                                                         player[i].lastseentime=1;
9143                                                                                                                                 }
9144                                                                                                 }
9145                                                                                                 if(player[i].lastseentime<0){
9146                                                                                                         //player[i].aitype=passivetype;
9147                                                                                                         numescaped++;
9148                                                                                                         player[i].aitype=pathfindtype;
9149                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9150                                                                                                         player[i].finalpathfindpoint=-1;
9151                                                                                                         player[i].targetpathfindpoint=-1;
9152                                                                                                         player[i].lastpathfindpoint=-1;
9153                                                                                                         player[i].lastpathfindpoint2=-1;
9154                                                                                                         player[i].lastpathfindpoint3=-1;
9155                                                                                                         player[i].lastpathfindpoint4=-1;
9156                                                                                                 }
9157                                                                                 }
9158
9159                                                                                 if(player[i].aitype!=gethelptype){
9160                                                                                         player[i].runninghowlong=0;
9161                                                                                 }
9162
9163                                                                                 if(player[i].aitype==gethelptype){
9164                                                                                         player[i].runninghowlong+=multiplier;
9165                                                                                         player[i].aiupdatedelay-=multiplier;
9166
9167                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9168                                                                                                 player[i].aiupdatedelay=.2;
9169
9170                                                                                                 int closest;
9171                                                                                                 float closestdist;
9172                                                                                                 closest=-1;
9173                                                                                                 closestdist=-1;
9174                                                                                                 float distance;
9175
9176                                                                                                 if(!player[i].ally){
9177                                                                                                         for(j=0;j<numplayers;j++){
9178                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9179                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9180                                                                                                                         if(closestdist==-1||distance<closestdist){
9181                                                                                                                                 closestdist=distance;
9182                                                                                                                                 closest=j;
9183                                                                                                                         }
9184                                                                                                                         closest=j;
9185                                                                                                                 }
9186                                                                                                         }
9187                                                                                                         if(closest!=-1)player[i].ally=closest;
9188                                                                                                         else player[i].ally=0;
9189                                                                                                         player[i].lastseen=player[0].coords;
9190                                                                                                         player[i].lastseentime=12;
9191                                                                                                 }
9192
9193
9194                                                                                                 player[i].lastchecktime=12;
9195                                                                                                 //player[i].lastseentime-=.5;
9196
9197                                                                                                 facing=player[i].coords;
9198                                                                                                 flatfacing=player[player[i].ally].coords;
9199                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9200                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9201                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9202                                                                                                         player[i].lastseentime-=.1;
9203
9204                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9205                                                                                                         player[i].aitype=searchtype;
9206                                                                                                         player[i].lastseentime=12;
9207                                                                                                 }
9208
9209                                                                                                 if(player[i].ally>0){
9210                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9211                                                                                                         Normalise(&rotatetarget);
9212                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9213                                                                                                         player[i].targetrotation*=360/6.28;
9214                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9215                                                                                                         player[i].lookrotation=player[i].targetrotation;
9216                                                                                                         player[i].aiupdatedelay=.05;
9217                                                                                                         player[i].forwardkeydown=1;
9218
9219                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9220                                                                                                                 player[i].aitype=searchtype;
9221                                                                                                                 player[i].lastseentime=12;
9222                                                                                                                 player[player[i].ally].aitype=searchtype;
9223                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9224                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9225                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9226                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9227                                                                                                                 }
9228                                                                                                         }
9229
9230                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9231                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9232                                                                                                                 else{
9233                                                                                                                         XYZ leftpos,rightpos;
9234                                                                                                                         float leftdist,rightdist;
9235                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9236                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9237                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9238                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9239                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9240                                                                                                                         else player[i].targetrotation-=90;
9241                                                                                                                 }
9242                                                                                                         }
9243                                                                                                 }
9244
9245                                                                                                 player[i].leftkeydown=0;
9246                                                                                                 player[i].backkeydown=0;
9247                                                                                                 player[i].rightkeydown=0;
9248                                                                                                 player[i].crouchkeydown=0;
9249                                                                                                 player[i].attackkeydown=0;
9250                                                                                         }
9251                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9252                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9253                                                                                 }
9254
9255                                                                                 if(player[i].aitype==getweapontype){
9256                                                                                         player[i].aiupdatedelay-=multiplier;
9257                                                                                         player[i].lastchecktime-=multiplier;
9258
9259                                                                                         if(player[i].aiupdatedelay<0){
9260                                                                                                 player[i].aiupdatedelay=.2;
9261
9262                                                                                                 int closest;
9263                                                                                                 float closestdist;
9264                                                                                                 closest=-1;
9265                                                                                                 closestdist=-1;
9266                                                                                                 float distance;
9267
9268                                                                                                 if(player[i].ally<0){
9269                                                                                                         for(j=0;j<weapons.numweapons;j++){
9270                                                                                                                 if(weapons.owner[j]==-1){
9271                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9272                                                                                                                         if(closestdist==-1||distance<closestdist){
9273                                                                                                                                 closestdist=distance;
9274                                                                                                                                 closest=j;
9275                                                                                                                         }
9276                                                                                                                         closest=j;
9277                                                                                                                 }
9278                                                                                                         }
9279                                                                                                         if(closest!=-1)player[i].ally=closest;
9280                                                                                                         else player[i].ally=-1;
9281                                                                                                 }
9282
9283                                                                                                 player[i].lastseentime=12;
9284
9285                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9286                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9287                                                                                                                 player[i].aitype=attacktypecutoff;
9288                                                                                                                 player[i].lastseentime=1;
9289                                                                                                         }
9290                                                                                                         if(!player[0].dead)
9291                                                                                                                 if(player[i].ally>=0){
9292                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9293                                                                                                                                 player[i].aitype=attacktypecutoff;
9294                                                                                                                                 player[i].lastseentime=1;
9295                                                                                                                         }
9296                                                                                                                         rotatetarget=weapons.position[player[i].ally]-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                                                                                                                         player[i].forwardkeydown=1;
9304
9305
9306                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9307                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9308                                                                                                                                 else{
9309                                                                                                                                         XYZ leftpos,rightpos;
9310                                                                                                                                         float leftdist,rightdist;
9311                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9312                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9313                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9314                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9315                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9316                                                                                                                                         else player[i].targetrotation-=90;
9317                                                                                                                                 }
9318                                                                                                                         }
9319                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9320                                                                                                                         if(abs(Random()%6)){
9321                                                                                                                         player[i].crouchkeydown=1;
9322                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9323                                                                                                                         if(player[i].isRun()){
9324                                                                                                                         player[i].targetframe=0;
9325                                                                                                                         player[i].target=0;
9326                                                                                                                         player[i].targetanimation=sneakanim;
9327                                                                                                                         }
9328                                                                                                                         }
9329                                                                                                                         else player[i].forwardkeydown=0;
9330                                                                                                                         }
9331                                                                                                                         else player[i].crouchkeydown=0;
9332                                                                                                                         }
9333                                                                                                                         else player[i].crouchkeydown=0;*/
9334                                                                                                                 }
9335
9336                                                                                                                 player[i].leftkeydown=0;
9337                                                                                                                 player[i].backkeydown=0;
9338                                                                                                                 player[i].rightkeydown=0;
9339                                                                                                                 player[i].attackkeydown=0;
9340                                                                                                                 player[i].throwkeydown=1;
9341                                                                                                                 player[i].crouchkeydown=0;
9342                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9343                                                                                                                 player[i].drawkeydown=0;
9344                                                                                         }
9345                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9346                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9347                                                                                 }
9348
9349                                                                                 if(player[i].aitype==attacktypecutoff){
9350                                                                                         player[i].aiupdatedelay-=multiplier;
9351                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9352                                                                                                 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)){
9353                                                                                                         player[i].attackkeydown=0;
9354                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9355                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9356                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9357                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9358                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9359                                                                                                                                 else player[i].targetanimation=rollanim;
9360                                                                                                                                 player[i].target=0;
9361                                                                                                                                 player[i].targetframe=0;
9362                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9363                                                                                                                                 player[i].wentforweapon=0;
9364                                                                                                                         }
9365                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9366                                                                                                                                 player[i].targetanimation=flipanim;
9367                                                                                                                                 player[i].target=0;
9368                                                                                                                                 player[i].targetframe=0;
9369                                                                                                                         }
9370                                                                                                                 }
9371                                                                                                         }
9372                                                                                                         player[i].forwardkeydown=0;
9373                                                                                                         player[i].aiupdatedelay=.02;
9374                                                                                                 }
9375                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9376                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9377                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9378                                                                                                 }
9379                                                                                                 if(player[i].wentforweapon<3)
9380                                                                                                         for(j=0;j<weapons.numweapons;j++){
9381                                                                                                                 if(player[i].creature!=wolftype)
9382                                                                                                                         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){
9383                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9384                                                                                                                                         player[i].wentforweapon++;
9385                                                                                                                                         player[i].lastchecktime=6;
9386                                                                                                                                         player[i].aitype=getweapontype;
9387                                                                                                                                         player[i].ally=-1;
9388                                                                                                                                 }
9389                                                                                                                         }
9390                                                                                                         }
9391                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9392                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9393                                                                                                                         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)))){
9394                                                                                                                                 player[i].crouchkeydown=1;
9395                                                                                                                         }
9396                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9397                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9398                                                                                                                                         test2=player[i].coords+player[i].facing;
9399                                                                                                                                         test2.y+=5;
9400                                                                                                                                         test=player[i].coords+player[i].facing;
9401                                                                                                                                         test.y-=10;
9402                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9403                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9404                                                                                                                                         if(j==-1){
9405                                                                                                                                                 player[i].velocity=0;
9406                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9407                                                                                                                                                 player[i].targetframe=0;
9408                                                                                                                                                 player[i].target=0;
9409                                                                                                                                                 player[i].targetrotation+=180;
9410                                                                                                                                                 player[i].stunned=.5;
9411                                                                                                                                                 //player[i].aitype=passivetype;
9412                                                                                                                                                 player[i].aitype=pathfindtype;
9413                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9414                                                                                                                                                 player[i].finalpathfindpoint=-1;
9415                                                                                                                                                 player[i].targetpathfindpoint=-1;
9416                                                                                                                                                 player[i].lastpathfindpoint=-1;
9417                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9418                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9419                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9420                                                                                                                                         }
9421                                                                                                                                         else player[i].laststanding=j;
9422                                                                                                                                 }
9423                                                                                                                         }
9424                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9425                                                                                                                                 player[i].aitype=pathfindtype;
9426                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9427                                                                                                                                 player[i].finalpathfindpoint=-1;
9428                                                                                                                                 player[i].targetpathfindpoint=-1;
9429                                                                                                                                 player[i].lastpathfindpoint=-1;
9430                                                                                                                                 player[i].lastpathfindpoint2=-1;
9431                                                                                                                                 player[i].lastpathfindpoint3=-1;
9432                                                                                                                                 player[i].lastpathfindpoint4=-1;
9433                                                                                                                         }
9434                                                                                                                         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){
9435                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9436                                                                                                                                 else player[i].drawkeydown=0;
9437                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9438                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9439                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9440                                                                                                                                         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;
9441                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9442                                                                                                                                 Normalise(&rotatetarget);
9443                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9444                                                                                                                                 player[i].targetrotation*=360/6.28;
9445                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9446                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9447                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9448
9449                                                                                                                                 oldkey=player[i].forwardkeydown;
9450                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9451                                                                                                                                 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;
9452                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9453                                                                                                                                 else player[i].forwardkeydown=0;
9454                                                                                                                                 if(player[0].dead){
9455                                                                                                                                         player[i].forwardkeydown=0;
9456                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9457                                                                                                                                         if(Random()%100==0){
9458                                                                                                                                                 player[i].aitype=pathfindtype;
9459                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9460                                                                                                                                                 player[i].finalpathfindpoint=-1;
9461                                                                                                                                                 player[i].targetpathfindpoint=-1;
9462                                                                                                                                                 player[i].lastpathfindpoint=-1;
9463                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9464                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9465                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9466                                                                                                                                         }
9467                                                                                                                                 }
9468                                                                                                                                 player[i].leftkeydown=0;
9469                                                                                                                                 player[i].backkeydown=0;
9470                                                                                                                                 player[i].rightkeydown=0;
9471                                                                                                                                 player[i].crouchkeydown=0;
9472                                                                                                                                 player[i].throwkeydown=0;
9473
9474                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9475                                                                                                                                 /*for(j=0;j<numplayers;j++){
9476                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9477                                                                                                                                 player[i].crouchkeydown=1;
9478                                                                                                                                 }
9479                                                                                                                                 }*/
9480                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9481                                                                                                                                 else player[i].attackkeydown=0;
9482                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9483                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9484                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9485                                                                                                                                 player[i].attackkeydown=0;
9486                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9487                                                                                                                                 player[i].forwardkeydown=0;
9488                                                                                                                                 player[i].aiupdatedelay=.02;
9489                                                                                                                                 }*/
9490
9491                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9492                                                                                                                                         target=-2;
9493                                                                                                                                         for(j=0;j<numplayers;j++){
9494                                                                                                                                                 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)){
9495                                                                                                                                                         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))))){
9496                                                                                                                                                                 if(target>=0)target=-1;
9497                                                                                                                                                                 else target=j;
9498                                                                                                                                                         }
9499                                                                                                                                                 }
9500                                                                                                                                         }
9501                                                                                                                                         if(target>=0)player[target].Reverse();
9502                                                                                                                                 }
9503
9504                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9505                                                                                                                                 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;
9506                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9507                                                                                                                                         player[0].jumpkeydown=0;
9508                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9509                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9510                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9511
9512                                                                                                                                 if(tutoriallevel==1){
9513                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9514                                                                                                                                 }
9515
9516
9517                                                                                                                                 facing=player[i].coords;
9518                                                                                                                                 flatfacing=player[0].coords;
9519                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9520                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9521                                                                                                                                 if(player[i].occluded>=2)
9522                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9523                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9524                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9525                                                                                                                                                         player[i].aitype=searchtype;
9526                                                                                                                                                         player[i].lastchecktime=12;
9527                                                                                                                                                         player[i].lastseen=player[0].coords;
9528                                                                                                                                                         player[i].lastseentime=12;
9529                                                                                                                                                 }
9530                                                                                                                                         }
9531                                                                                                                                         else player[i].lastseentime=1;
9532                                                                                                                         }
9533                                                                                 }
9534                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9535                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9536                                                                                                 test=player[0].coords;
9537                                                                                                 test.y-=40;
9538                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9539                                                                                         }
9540                                                                                 }
9541                                                                                 // NOTE: Ask about logic of this call : NOTE
9542                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9543                                                                                         player[i].stunned>0 ||
9544                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9545                                                                                 {
9546                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9547                                                                                         player[i].targetrotation=player[i].rotation;
9548                                                                                         player[i].forwardkeydown=0;
9549                                                                                         player[i].leftkeydown=0;
9550                                                                                         player[i].backkeydown=0;
9551                                                                                         player[i].rightkeydown=0;
9552                                                                                         player[i].jumpkeydown=0;
9553                                                                                         player[i].attackkeydown=0;
9554                                                                                         player[i].crouchkeydown=0;
9555                                                                                         player[i].throwkeydown=0;
9556                                                                                 }
9557
9558
9559                                                                                 facing=0;
9560                                                                                 facing.z=-1;
9561
9562                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9563                                                                                 facing=flatfacing;
9564
9565                                                                                 if(player[i].aitype==attacktypecutoff){
9566                                                                                         rotatetarget=player[0].coords-player[i].coords;
9567                                                                                         Normalise(&rotatetarget);
9568                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9569                                                                                         player[i].targetheadrotation*=360/6.28;
9570                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9571
9572                                                                                         player[i].targetheadrotation*=-1;
9573                                                                                         player[i].targetheadrotation+=180;
9574                                                                                         //player[i].targetheadrotation2=0;
9575                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9576                                                                                 }
9577                                                                                 else if(player[i].howactive>=typesleeping){
9578                                                                                         player[i].targetheadrotation=player[i].targetrotation;
9579                                                                                         player[i].targetheadrotation2=0;
9580                                                                                 }
9581                                                                                 else {
9582                                                                                         if(player[i].interestdelay<=0){
9583                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
9584                                                                                                 player[i].headtarget=player[i].coords;
9585                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
9586                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
9587                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
9588                                                                                                 player[i].headtarget+=player[i].facing*1.5;
9589                                                                                         }
9590                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
9591                                                                                         Normalise(&rotatetarget);
9592                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9593                                                                                         player[i].targetheadrotation*=360/6.28;
9594                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9595
9596                                                                                         player[i].targetheadrotation*=-1;
9597                                                                                         player[i].targetheadrotation+=180;
9598                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9599                                                                                 }
9600                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
9601                                                                         }
9602                                                                         if(animation[player[i].targetanimation].attack==reversed){
9603                                                                                 //player[i].targetrotation=player[i].rotation;
9604                                                                                 player[i].forwardkeydown=0;
9605                                                                                 player[i].leftkeydown=0;
9606                                                                                 player[i].backkeydown=0;
9607                                                                                 player[i].rightkeydown=0;
9608                                                                                 player[i].jumpkeydown=0;
9609                                                                                 player[i].attackkeydown=0;
9610                                                                                 //player[i].crouchkeydown=0;
9611                                                                                 player[i].throwkeydown=0;
9612                                                                         }
9613
9614                                                                         if(indialogue!=-1){
9615                                                                                 player[i].forwardkeydown=0;
9616                                                                                 player[i].leftkeydown=0;
9617                                                                                 player[i].backkeydown=0;
9618                                                                                 player[i].rightkeydown=0;
9619                                                                                 player[i].jumpkeydown=0;
9620                                                                                 player[i].crouchkeydown=0;
9621                                                                                 player[i].drawkeydown=0;
9622                                                                                 player[i].throwkeydown=0;
9623                                                                         }
9624
9625                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
9626                                                                         if(player[i].collided>1)player[i].collided=1;
9627                                                                         player[i].collided-=multiplier*4;
9628                                                                         player[i].whichdirectiondelay-=multiplier;
9629                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
9630                                                                                 player[i].avoidcollided=-.3;
9631                                                                                 player[i].whichdirection=abs(Random()%2);
9632                                                                                 player[i].whichdirectiondelay=.4;
9633                                                                         }
9634                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
9635                                                                         player[i].avoidcollided-=multiplier/4;
9636                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
9637                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
9638                                                                         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;
9639
9640                                                                         if(!player[i].throwkeydown){
9641                                                                                 player[i].throwtogglekeydown=0;
9642                                                                         }
9643                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
9644                                                                                 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)){
9645                                                                                         for(j=0;j<weapons.numweapons;j++){
9646                                                                                                 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)
9647                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
9648                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
9649                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
9650                                                                                                                                 player[i].throwtogglekeydown=1;
9651                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
9652                                                                                                                                 player[i].target=0;
9653                                                                                                                                 player[i].targetframe=0;
9654                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
9655                                                                                                                                 Normalise(&rotatetarget);
9656                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9657                                                                                                                                 player[i].targetrotation*=360/6.28;
9658                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9659                                                                                                                                 player[i].hasvictim=0;
9660                                                                                                                         }
9661                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9662                                                                                                                                 player[i].throwtogglekeydown=1;
9663                                                                                                                                 player[i].hasvictim=0;
9664
9665                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
9666                                                                                                                                 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))
9667                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
9668                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
9669                                                                                                                                                         float gLoc[3];
9670                                                                                                                                                         float vel[3];
9671                                                                                                                                                         gLoc[0]=player[i].coords.x;
9672                                                                                                                                                         gLoc[1]=player[i].coords.y;
9673                                                                                                                                                         gLoc[2]=player[i].coords.z;
9674                                                                                                                                                         vel[0]=player[i].velocity.x;
9675                                                                                                                                                         vel[1]=player[i].velocity.y;
9676                                                                                                                                                         vel[2]=player[i].velocity.z;
9677                                                                                                                                                         if(weapons.type[j]!=staff){
9678                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9679                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9680                                                                                                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
9681                                                                                                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
9682                                                                                                                                                         }
9683
9684                                                                                                                                                         player[i].weaponactive=0;
9685                                                                                                                                                         weapons.owner[j]=player[i].id;
9686                                                                                                                                                         if(player[i].num_weapons>0){
9687                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9688                                                                                                                                                         }
9689                                                                                                                                                         player[i].num_weapons++;
9690                                                                                                                                                         player[i].weaponids[0]=j;
9691                                                                                                                                                 }
9692                                                                                                                                         }
9693                                                                                                                                         //}
9694                                                                                                                         }
9695                                                                                                                 }
9696                                                                                                                 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){
9697                                                                                                                         if(!player[i].isFlip()){
9698                                                                                                                                 player[i].throwtogglekeydown=1;
9699                                                                                                                                 player[i].targetanimation=removeknifeanim;
9700                                                                                                                                 player[i].target=0;
9701                                                                                                                                 player[i].targetframe=0;
9702                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
9703                                                                                                                                 Normalise(&rotatetarget);
9704                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9705                                                                                                                                 player[i].targetrotation*=360/6.28;
9706                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9707                                                                                                                         }
9708                                                                                                                         if(player[i].isFlip()){
9709                                                                                                                                 player[i].throwtogglekeydown=1;
9710                                                                                                                                 player[i].hasvictim=0;
9711
9712                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
9713                                                                                                                                         if(player[i].weaponactive==-1)
9714                                                                                                                                                 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))
9715                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
9716                                                                                                                                                                 float gLoc[3];
9717                                                                                                                                                                 float vel[3];
9718                                                                                                                                                                 gLoc[0]=player[i].coords.x;
9719                                                                                                                                                                 gLoc[1]=player[i].coords.y;
9720                                                                                                                                                                 gLoc[2]=player[i].coords.z;
9721                                                                                                                                                                 vel[0]=player[i].velocity.x;
9722                                                                                                                                                                 vel[1]=player[i].velocity.y;
9723                                                                                                                                                                 vel[2]=player[i].velocity.z;
9724                                                                                                                                                                 if(weapons.type[k]!=staff){
9725                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9726                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9727                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
9728                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
9729                                                                                                                                                                 }
9730
9731                                                                                                                                                                 player[i].weaponactive=0;
9732                                                                                                                                                                 weapons.owner[k]=player[i].id;
9733                                                                                                                                                                 if(player[i].num_weapons>0){
9734                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9735                                                                                                                                                                 }
9736                                                                                                                                                                 player[i].num_weapons++;
9737                                                                                                                                                                 player[i].weaponids[0]=k;
9738                                                                                                                                                         }
9739                                                                                                                                 }
9740                                                                                                                         }
9741                                                                                                                 }
9742                                                                                                         }
9743                                                                                         }
9744                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9745                                                                                                 if(numplayers>1)
9746                                                                                                         for(j=0;j<numplayers;j++){
9747                                                                                                                 if(player[i].weaponactive==-1)
9748                                                                                                                         if(j!=i)
9749                                                                                                                                 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)){
9750                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
9751                                                                                                                                                 player[i].throwtogglekeydown=1;
9752                                                                                                                                                 player[i].victim=&player[j];
9753                                                                                                                                                 player[i].hasvictim=1;
9754                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
9755                                                                                                                                                 player[i].target=0;
9756                                                                                                                                                 player[i].targetframe=0;
9757                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
9758                                                                                                                                                 Normalise(&rotatetarget);
9759                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9760                                                                                                                                                 player[i].targetrotation*=360/6.28;
9761                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9762                                                                                                                                         }
9763                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9764                                                                                                                                                 player[i].throwtogglekeydown=1;
9765                                                                                                                                                 player[i].victim=&player[j];
9766                                                                                                                                                 player[i].hasvictim=1;
9767                                                                                                                                                 int k = player[j].weaponids[0];
9768                                                                                                                                                 if(player[i].hasvictim){
9769                                                                                                                                                         float gLoc[3];
9770                                                                                                                                                         float vel[3];
9771                                                                                                                                                         gLoc[0]=player[i].coords.x;
9772                                                                                                                                                         gLoc[1]=player[i].coords.y;
9773                                                                                                                                                         gLoc[2]=player[i].coords.z;
9774                                                                                                                                                         vel[0]=player[i].velocity.x;
9775                                                                                                                                                         vel[1]=player[i].velocity.y;
9776                                                                                                                                                         vel[2]=player[i].velocity.z;
9777                                                                                                                                                         bool fleshstuck;
9778                                                                                                                                                         fleshstuck=0;
9779                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
9780                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
9781                                                                                                                                                                         fleshstuck=1;
9782                                                                                                                                                                 }
9783                                                                                                                                                         }
9784                                                                                                                                                         if(!fleshstuck){
9785                                                                                                                                                                 if(weapons.type[k]!=staff){
9786                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9787                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9788                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
9789                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
9790                                                                                                                                                                 }
9791                                                                                                                                                         }
9792                                                                                                                                                         if(fleshstuck){
9793                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
9794                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
9795                                                                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
9796                                                                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
9797                                                                                                                                                         }
9798
9799                                                                                                                                                         player[i].weaponactive=0;
9800                                                                                                                                                         if(weapons.owner[k]!=-1){
9801                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
9802                                                                                                                                                                 else player[i].victim->num_weapons=1;
9803
9804                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
9805                                                                                                                                                                 player[i].victim->skeleton.free=1;
9806                                                                                                                                                                 player[i].victim->skeleton.broken=0;
9807
9808                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
9809                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
9810                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
9811                                                                                                                                                                 }
9812
9813                                                                                                                                                                 XYZ relative;
9814                                                                                                                                                                 relative=0;
9815                                                                                                                                                                 relative.y=10;
9816                                                                                                                                                                 Normalise(&relative);
9817                                                                                                                                                                 XYZ footvel,footpoint;
9818                                                                                                                                                                 footvel=0;
9819                                                                                                                                                                 footpoint=weapons.position[k];
9820                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
9821                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
9822                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
9823                                                                                                                                                                                 weapons.bloody[k]=2;
9824                                                                                                                                                                                 weapons.blooddrip[k]=5;
9825                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
9826                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
9827                                                                                                                                                                                 player[i].victim->DoDamage(2000);
9828                                                                                                                                                                         }
9829                                                                                                                                                                 }
9830                                                                                                                                                                 if(player[i].victim->num_weapons>0){
9831                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
9832                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
9833                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
9834                                                                                                                                                                 }
9835
9836                                                                                                                                                                 player[i].victim->weaponactive=-1;
9837
9838                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
9839                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
9840                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
9841                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
9842                                                                                                                                                         }
9843                                                                                                                                                         weapons.owner[k]=i;
9844                                                                                                                                                         if(player[i].num_weapons>0){
9845                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9846                                                                                                                                                         }
9847                                                                                                                                                         player[i].num_weapons++;
9848                                                                                                                                                         player[i].weaponids[0]=k;
9849                                                                                                                                                 }
9850                                                                                                                                         }
9851                                                                                                                                 }
9852                                                                                                         }
9853                                                                                         }
9854                                                                                 }
9855                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
9856                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
9857                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
9858                                                                                                         if(numplayers>1)
9859                                                                                                                 for(j=0;j<numplayers;j++){
9860                                                                                                                         if(i!=j)
9861                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
9862                                                                                                                                         if(hostile)
9863                                                                                                                                                 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)){
9864                                                                                                                                                         if(!player[i].isFlip()){
9865                                                                                                                                                                 player[i].throwtogglekeydown=1;
9866                                                                                                                                                                 player[i].victim=&player[j];
9867                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
9868                                                                                                                                                                 player[i].target=0;
9869                                                                                                                                                                 player[i].targetframe=0;
9870                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
9871                                                                                                                                                                 Normalise(&rotatetarget);
9872                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9873                                                                                                                                                                 player[i].targetrotation*=360/6.28;
9874                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9875
9876                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
9877                                                                                                                                                         }
9878                                                                                                                                                         if(player[i].isFlip()){
9879                                                                                                                                                                 if(player[i].weaponactive!=-1){
9880                                                                                                                                                                         player[i].throwtogglekeydown=1;
9881                                                                                                                                                                         player[i].victim=&player[j];
9882                                                                                                                                                                         XYZ aim;
9883                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
9884                                                                                                                                                                         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);
9885                                                                                                                                                                         Normalise(&aim);
9886
9887                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
9888
9889                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
9890                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
9891                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
9892                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
9893                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
9894                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
9895                                                                                                                                                                         player[i].num_weapons--;
9896                                                                                                                                                                         if(player[i].num_weapons){
9897                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
9898                                                                                                                                                                         }
9899                                                                                                                                                                         player[i].weaponactive=-1;
9900                                                                                                                                                                 }
9901                                                                                                                                                         }
9902                                                                                                                                                 }
9903                                                                                                                 }
9904                                                                                         }
9905                                                                                 }
9906                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
9907                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
9908                                                                                         {
9909                                                                                                 player[i].throwtogglekeydown=1;
9910                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
9911                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
9912                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
9913                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
9914                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
9915                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
9916                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
9917                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
9918                                                                                                 player[i].num_weapons--;
9919                                                                                                 if(player[i].num_weapons){
9920                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
9921                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
9922                                                                                                 }
9923
9924                                                                                                 player[i].weaponactive=-1;
9925                                                                                                 for(j=0;j<numplayers;j++){
9926                                                                                                         player[j].wentforweapon=0;
9927                                                                                                 }
9928                                                                                         }
9929                                                                                 }
9930
9931                                                                         }
9932
9933                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
9934                                                                                 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)){
9935                                                                                         //Setenvironment(1-environment);
9936                                                                                         bool isgood;
9937                                                                                         isgood=1;
9938                                                                                         if(player[i].weaponactive!=-1){
9939                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
9940                                                                                         }
9941                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
9942                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
9943                                                                                                         player[i].targetanimation=drawrightanim;
9944                                                                                                         player[i].targetframe=0;
9945                                                                                                         player[i].target=0;
9946                                                                                                         player[i].drawtogglekeydown=1;
9947                                                                                                 }
9948                                                                                                 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){
9949                                                                                                         player[i].targetanimation=drawleftanim;
9950                                                                                                         player[i].targetframe=0;
9951                                                                                                         player[i].target=0;
9952                                                                                                         player[i].drawtogglekeydown=1;
9953                                                                                                 }
9954                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
9955                                                                                                         player[i].targetanimation=crouchdrawrightanim;
9956                                                                                                         player[i].targetframe=0;
9957                                                                                                         player[i].target=0;
9958                                                                                                         player[i].drawtogglekeydown=1;
9959                                                                                                 }
9960                                                                                         }
9961                                                                                 }
9962                                                                                 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){
9963                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
9964                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
9965                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
9966                                                                                                 player[i].targetframe=0;
9967                                                                                                 player[i].target=0;
9968                                                                                                 player[i].hasvictim=0;
9969                                                                                                 //player[i].attacktogglekeydown=1;
9970                                                                                         }
9971                                                                                 }
9972
9973                                                                                 if(!player[i].drawkeydown){
9974                                                                                         player[i].drawtogglekeydown=0;
9975                                                                                 }
9976
9977                                                                                 if(i==0){
9978                                                                                         absflatfacing=0;
9979                                                                                         absflatfacing.z=-1;
9980
9981                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
9982                                                                                 }
9983                                                                                 else absflatfacing=flatfacing;
9984
9985                                                                                 if(indialogue!=-1){
9986                                                                                         player[i].forwardkeydown=0;
9987                                                                                         player[i].leftkeydown=0;
9988                                                                                         player[i].backkeydown=0;
9989                                                                                         player[i].rightkeydown=0;
9990                                                                                         player[i].jumpkeydown=0;
9991                                                                                         player[i].crouchkeydown=0;
9992                                                                                         player[i].drawkeydown=0;
9993                                                                                         player[i].throwkeydown=0;
9994                                                                                 }
9995                                                                                 movekey=0;
9996                                                                                 //Do controls
9997                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
9998                                                                                         if(!player[i].forwardkeydown){
9999                                                                                                 player[i].forwardstogglekeydown=0;
10000                                                                                         }
10001                                                                                         if(player[i].crouchkeydown){
10002                                                                                                 //Crouch
10003                                                                                                 target=-2;
10004                                                                                                 if(i==0){
10005                                                                                                         player[i].superruntoggle=1;
10006                                                                                                         if(numplayers>1)
10007                                                                                                                 for(j=0;j<numplayers;j++){
10008                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10009                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10010                                                                                                                                         player[i].superruntoggle=0;
10011                                                                                                                                 }
10012                                                                                                                         }
10013                                                                                                                 }
10014                                                                                                 }
10015
10016                                                                                                 if(numplayers>1)
10017                                                                                                         for(j=0;j<numplayers;j++){
10018                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10019                                                                                                                         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))){
10020                                                                                                                                 if(target>=0)target=-1;
10021                                                                                                                                 else target=j;
10022                                                                                                                         }
10023                                                                                                                 }
10024                                                                                                         }
10025                                                                                                         if(target>=0)player[target].Reverse();
10026                                                                                                         player[i].lowreversaldelay=.5;
10027
10028                                                                                                         if(player[i].isIdle()){
10029                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10030                                                                                                                 player[i].target=0;
10031                                                                                                                 player[i].targetframe=0;
10032                                                                                                                 player[i].transspeed=10;
10033                                                                                                         }
10034                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10035                                                                                                                 player[i].targetanimation=rollanim;
10036                                                                                                                 player[i].target=0;
10037                                                                                                                 player[i].targetframe=0;
10038                                                                                                                 player[i].transspeed=20;
10039                                                                                                         }
10040                                                                                         }
10041                                                                                         if(!player[i].crouchkeydown){
10042                                                                                                 //Uncrouch
10043                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10044                                                                                                 target=-2;
10045                                                                                                 if(player[i].isCrouch()){
10046                                                                                                         if(numplayers>1)
10047                                                                                                                 for(j=0;j<numplayers;j++){
10048                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10049                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10050                                                                                                                                         if(target>=0)target=-1;
10051                                                                                                                                         else target=j;
10052                                                                                                                                 }
10053                                                                                                                         }
10054                                                                                                                 }
10055                                                                                                                 if(target>=0)player[target].Reverse();
10056                                                                                                                 player[i].highreversaldelay=.5;
10057
10058                                                                                                                 if(player[i].isCrouch()){
10059                                                                                                                         if(!player[i].wasCrouch()){
10060                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10061                                                                                                                                 player[i].currentframe=0;
10062                                                                                                                         }
10063                                                                                                                         player[i].target=0;
10064                                                                                                                         player[i].targetanimation=player[i].getIdle();
10065                                                                                                                         player[i].targetframe=0;
10066                                                                                                                         player[i].transspeed=10;
10067                                                                                                                 }
10068                                                                                                 }
10069                                                                                                 if(player[i].targetanimation==sneakanim){
10070                                                                                                         player[i].targetanimation=player[i].getIdle();
10071                                                                                                         player[i].target=0;
10072                                                                                                         player[i].targetframe=0;
10073                                                                                                         player[i].transspeed=10;
10074                                                                                                 }
10075                                                                                         }
10076                                                                                         if(player[i].forwardkeydown){
10077                                                                                                 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)){
10078                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10079                                                                                                         else player[i].targetanimation=player[i].getRun();
10080                                                                                                         player[i].target=0;
10081                                                                                                         player[i].targetframe=0;
10082                                                                                                 }
10083                                                                                                 if(player[i].isCrouch()){
10084                                                                                                         player[i].targetanimation=sneakanim;
10085                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10086                                                                                                         player[i].targetframe=0;
10087                                                                                                 }
10088                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10089                                                                                                         player[i].targetanimation=climbanim;
10090                                                                                                         player[i].target=0;
10091                                                                                                         player[i].targetframe=1;
10092                                                                                                         player[i].jumpclimb=1;
10093                                                                                                 }
10094                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10095                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10096                                                                                                 }
10097                                                                                                 player[i].forwardstogglekeydown=1;
10098                                                                                                 movekey=1;
10099                                                                                         }
10100                                                                                         if (player[i].rightkeydown){
10101                                                                                                 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)){
10102                                                                                                         player[i].targetanimation=player[i].getRun();
10103                                                                                                         player[i].target=0;
10104                                                                                                         player[i].targetframe=0;
10105                                                                                                 }
10106                                                                                                 if(player[i].isCrouch()){
10107                                                                                                         player[i].targetanimation=sneakanim;
10108                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10109                                                                                                         player[i].targetframe=0;
10110                                                                                                 }
10111                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10112                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10113                                                                                                 }
10114                                                                                                 player[i].targetrotation-=90;
10115                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10116                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10117                                                                                                 movekey=1;
10118                                                                                         }
10119                                                                                         if ( player[i].leftkeydown){
10120                                                                                                 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)){
10121                                                                                                         player[i].targetanimation=player[i].getRun();
10122                                                                                                         player[i].target=0;
10123                                                                                                         player[i].targetframe=0;
10124                                                                                                 }
10125                                                                                                 if(player[i].isCrouch()){
10126                                                                                                         player[i].targetanimation=sneakanim;
10127                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10128                                                                                                         player[i].targetframe=0;
10129                                                                                                 }
10130                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10131                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10132                                                                                                 }
10133                                                                                                 player[i].targetrotation+=90;
10134                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10135                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10136                                                                                                 movekey=1;
10137                                                                                         }
10138                                                                                         if(player[i].backkeydown){
10139                                                                                                 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)){
10140                                                                                                         player[i].targetanimation=player[i].getRun();
10141                                                                                                         player[i].target=0;
10142                                                                                                         player[i].targetframe=0;
10143                                                                                                 }
10144                                                                                                 if(player[i].isCrouch()){
10145                                                                                                         player[i].targetanimation=sneakanim;
10146                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10147                                                                                                         player[i].targetframe=0;
10148                                                                                                 }
10149                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10150                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10151                                                                                                 }
10152                                                                                                 if(player[i].targetanimation==hanganim){
10153                                                                                                         player[i].currentanimation=jumpdownanim;
10154                                                                                                         player[i].targetanimation=jumpdownanim;
10155                                                                                                         player[i].target=0;
10156                                                                                                         player[i].currentframe=0;
10157                                                                                                         player[i].targetframe=1;
10158                                                                                                         player[i].velocity=0;
10159                                                                                                         player[i].velocity.y+=gravity;
10160                                                                                                         player[i].coords.y-=1.4;
10161                                                                                                         player[i].grabdelay=1;
10162                                                                                                 }
10163                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10164                                                                                                         player[i].targetrotation+=180;
10165                                                                                                 movekey=1;
10166                                                                                         }
10167                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10168                                                                                                 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)){
10169                                                                                                         player[i].jumpstart=0;
10170                                                                                                         player[i].targetanimation=jumpupanim;
10171                                                                                                         player[i].target=0;
10172                                                                                                         player[i].targetframe=0;
10173                                                                                                         player[i].rotation=player[i].targetrotation;
10174                                                                                                         player[i].transspeed=20;
10175                                                                                                         player[i].FootLand(0,1);
10176                                                                                                         player[i].FootLand(1,1);
10177
10178                                                                                                         facing=0;
10179                                                                                                         facing.z=-1;
10180                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10181
10182                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10183                                                                                                         if(!movekey)player[i].velocity=0;
10184
10185                                                                                                         //Dodge sweep?
10186                                                                                                         target=-2;
10187                                                                                                         if(numplayers>1)
10188                                                                                                                 for(j=0;j<numplayers;j++){
10189                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10190                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10191                                                                                                                                         if(target>=0)target=-1;
10192                                                                                                                                         else target=j;
10193                                                                                                                                 }
10194                                                                                                                         }
10195                                                                                                                 }
10196                                                                                                                 if(target>=0)player[i].velocity.y=1;
10197                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10198                                                                                                                         player[i].velocity.y=7;
10199                                                                                                                         player[i].crouchtogglekeydown=1;
10200                                                                                                                 }
10201                                                                                                                 else player[i].velocity.y=5;
10202
10203                                                                                                                 if(mousejump&&i==0&&debugmode){
10204                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10205                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10206                                                                                                                 }
10207
10208                                                                                                                 player[i].coords.y+=.2;
10209                                                                                                                 player[i].jumppower-=1;
10210
10211                                                                                                                 static float gLoc[3];
10212                                                                                                                 static float vel[3];
10213                                                                                                                 gLoc[0]=player[i].coords.x;
10214                                                                                                                 gLoc[1]=player[i].coords.y;
10215                                                                                                                 gLoc[2]=player[i].coords.z;
10216                                                                                                                 vel[0]=player[i].velocity.x;
10217                                                                                                                 vel[1]=player[i].velocity.y;
10218                                                                                                                 vel[2]=player[i].velocity.z;
10219
10220                                                                                                                 if(i==0){
10221                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
10222                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10223                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
10224                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
10225                                                                                                                 }
10226
10227                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
10228                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10229                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
10230                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
10231                                                                                                 }
10232                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10233                                                                                                         player[i].targetanimation=player[i].getLanding();
10234                                                                                                         player[i].landhard=0;
10235                                                                                                         player[i].target=0;
10236                                                                                                         player[i].targetframe=2;
10237                                                                                                         player[i].jumpstart=1;
10238                                                                                                         player[i].tempdeltav=deltav;
10239                                                                                                 }
10240                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10241                                                                                                         if(player[i].jumppower>multiplier*6){
10242                                                                                                                 player[i].velocity.y+=multiplier*6;
10243                                                                                                                 player[i].jumppower-=multiplier*6;
10244                                                                                                         }
10245                                                                                                         if(player[i].jumppower<=multiplier*6){
10246                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10247                                                                                                                 player[i].jumppower=0;
10248                                                                                                         }
10249                                                                                                 }
10250                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
10251                                                                                         }
10252
10253                                                                                         if(!movekey){
10254                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10255                                                                                                         player[i].targetanimation=player[i].getStop();
10256                                                                                                         player[i].target=0;
10257                                                                                                         player[i].targetframe=0;
10258                                                                                                 }
10259                                                                                                 if(player[i].targetanimation==sneakanim){
10260                                                                                                         player[i].targetanimation=player[i].getCrouch();
10261                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10262                                                                                                         player[i].targetframe=0;
10263                                                                                                 }
10264                                                                                         }
10265                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10266                                                                                                 player[i].targetanimation=player[i].getStop();
10267                                                                                                 player[i].target=0;
10268                                                                                                 player[i].targetframe=0;
10269                                                                                         }
10270                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10271                                                                                                 player[i].targetanimation=player[i].getStop();
10272                                                                                                 player[i].target=0;
10273                                                                                                 player[i].targetframe=0;
10274                                                                                         }
10275                                                                                 }
10276                                                                 }
10277                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10278                                                         }
10279
10280                                                         //Rotation
10281                                                         for(k=0;k<numplayers;k++){
10282                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10283                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10284                                                                         else player[k].rotation+=360;
10285                                                                 }
10286
10287                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10288                                                                         player[k].targetanimation=player[k].getStop();
10289                                                                         player[k].targetframe=0;
10290                                                                         player[k].target=0;
10291                                                                 }
10292
10293                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10294                                                                         player[k].targettilt=0;
10295                                                                 }
10296                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10297                                                                         player[k].targettilt=0;
10298                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10299                                                                         player[k].jumppower+=multiplier*7;
10300                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10301                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10302                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10303                                                                 }
10304
10305                                                                 if(player[k].isRun()){
10306                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10307                                                                 }
10308
10309                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10310                                                                 else if(player[k].tilt>player[k].targettilt){
10311                                                                         player[k].tilt-=multiplier*150;
10312                                                                 }
10313                                                                 else if(player[k].tilt<player[k].targettilt){
10314                                                                         player[k].tilt+=multiplier*150;
10315                                                                 }
10316
10317                                                                 player[k].grabdelay-=multiplier;
10318                                                         }
10319
10320                                                         for(k=0;k<numplayers;k++){
10321                                                                 player[k].DoAnimations();
10322                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10323                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10324                                                         }
10325
10326                                                         objects.DoStuff();
10327                                                         /*
10328                                                         player[0].righthandmorphstart=0;
10329                                                         player[0].righthandmorphend=1;
10330                                                         player[0].lefthandmorphstart=0;
10331                                                         player[0].lefthandmorphend=1;
10332                                                         player[0].headmorphstart=0;
10333                                                         player[0].headmorphend=2;*/
10334
10335                                                         /*
10336                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10337                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10338                                                         player[0].righthandmorphend=1;
10339                                                         player[0].targetrighthandmorphness=1;
10340
10341                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10342                                                         player[0].lefthandmorphend=0;
10343                                                         player[0].targetlefthandmorphness=1;
10344
10345                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10346                                                         player[0].headmorphend=2;
10347                                                         player[0].targetheadmorphness=1;
10348                                                         }
10349                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10350                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10351                                                         player[0].righthandmorphend=0;
10352                                                         player[0].targetrighthandmorphness=1;
10353
10354                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10355                                                         player[0].lefthandmorphend=1;
10356                                                         player[0].targetlefthandmorphness=1;
10357
10358                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10359                                                         player[0].headmorphend=0;
10360                                                         player[0].targetheadmorphness=1;
10361                                                         }
10362                                                         */
10363                                                         if(numenvsounds!=0)
10364                                                                 for(j=numenvsounds-1;j>=0;j--){
10365                                                                         envsoundlife[j]-=multiplier;
10366                                                                         if(envsoundlife[j]<0){
10367                                                                                 numenvsounds--;
10368                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10369                                                                                 envsound[j]=envsound[numenvsounds];
10370                                                                         }
10371                                                                 }
10372                                                                 if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
10373                                                                 if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
10374
10375                                                                 if(tutoriallevel==1){
10376                                                                         XYZ temp;
10377                                                                         XYZ temp2;
10378                                                                         XYZ temp3;
10379                                                                         XYZ oldtemp;
10380                                                                         XYZ oldtemp2;
10381                                                                         temp.x=1011;
10382                                                                         temp.y=84;
10383                                                                         temp.z=491;
10384                                                                         temp2.x=1025;
10385                                                                         temp2.y=75;
10386                                                                         temp2.z=447;
10387                                                                         temp3.x=1038;
10388                                                                         temp3.y=76;
10389                                                                         temp3.z=453;
10390                                                                         oldtemp=temp;
10391                                                                         oldtemp2=temp2;
10392                                                                         if(tutorialstage>=51)
10393                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10394                                                     OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
10395                                                                                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
10396
10397                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10398                                                                                         OPENAL_SetPaused(channels[stream_music3], false);
10399                                                                                         OPENAL_SetVolume(channels[stream_music3], 256);
10400
10401                                                                                         gameon=0;
10402                                                                                         mainmenu=5;
10403
10404                                                                                         float gLoc[3]={0,0,0};
10405                                                                                         float vel[3]={0,0,0};
10406                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10407                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10408                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10409                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10410                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10411                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10412
10413                                                                                         flashr=1;
10414                                                                                         flashg=0;
10415                                                                                         flashb=0;
10416                                                                                         flashamount=1;
10417                                                                                         flashdelay=1;
10418                                                                                 }
10419                                                                                 if(tutorialstage<51)
10420                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10421                                                                                                 float gLoc[3];
10422                                                                                                 float vel[3];
10423                                                                                                 gLoc[0]=player[0].coords.x;
10424                                                                                                 gLoc[1]=player[0].coords.y;
10425                                                                                                 gLoc[2]=player[0].coords.z;
10426                                                                                                 vel[0]=0;
10427                                                                                                 vel[1]=0;
10428                                                                                                 vel[2]=0;
10429                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10430                                                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10431                                                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10432                                                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10433
10434                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10435
10436                                                                                                 flashr=1;
10437                                                                                                 flashg=1;
10438                                                                                                 flashb=1;
10439                                                                                                 flashamount=1;
10440                                                                                                 flashdelay=1;
10441                                                                                         }
10442                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10443                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10444                                                                                                         float gLoc[3];
10445                                                                                                         float vel[3];
10446                                                                                                         gLoc[0]=player[1].coords.x;
10447                                                                                                         gLoc[1]=player[1].coords.y;
10448                                                                                                         gLoc[2]=player[1].coords.z;
10449                                                                                                         vel[0]=0;
10450                                                                                                         vel[1]=0;
10451                                                                                                         vel[2]=0;
10452                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10453                                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10454                                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10455                                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10456
10457                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10458                                                                                                                 if(Random()%2==0){
10459                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10460                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10461                                                                                                                         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;
10462                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10463                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10464                                                                                                                 }
10465                                                                                                         }
10466
10467                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10468                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10469                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10470                                                                                                                 if(Random()%2==0){
10471                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10472                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10473                                                                                                                         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;
10474                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10475                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10476                                                                                                                 }
10477                                                                                                         }
10478                                                                                                 }
10479                                                                 }
10480
10481
10482                                                                 //3d sound
10483                                                                 static float gLoc[3];
10484                                                                 gLoc[0]=viewer.x;
10485                                                                 gLoc[1]=viewer.y;
10486                                                                 gLoc[2]=viewer.z;
10487                                                                 static float vel[3];
10488                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10489                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10490                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10491
10492                                                                 //Set orientation with forward and up vectors
10493                                                                 static XYZ upvector;
10494                                                                 upvector=0;
10495                                                                 upvector.z=-1;
10496
10497                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10498                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10499
10500                                                                 facing=0;
10501                                                                 facing.z=-1;
10502
10503                                                                 facing=DoRotation(facing,-rotation2,0,0);
10504                                                                 facing=DoRotation(facing,0,0-rotation,0);
10505
10506
10507                                                                 static float ori[6];
10508                                                                 ori[0] = -facing.x;
10509                                                                 ori[1] = facing.y;
10510                                                                 ori[2] = -facing.z;
10511                                                                 ori[3] = -upvector.x;
10512                                                                 ori[4] = upvector.y;
10513                                                                 ori[5] = -upvector.z;
10514
10515                                                                 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10516                                                                 OPENAL_Update();
10517
10518                                                                 oldviewer=viewer;
10519                 }
10520         }
10521
10522         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10523                 Screenshot();
10524                 freezetogglekeydown=1;
10525         }
10526 }
10527
10528 void    Game::TickOnce(){
10529         //if(!console){
10530         if(!mainmenu)
10531                 if(directing||indialogue==-1){
10532                         rotation+=deltah*.7;
10533                         if(!invertmouse)rotation2+=deltav*.7;
10534                         if(invertmouse)rotation2-=deltav*.7;
10535                         if(rotation2>90)rotation2=90;
10536                         if(rotation2<-70)rotation2=-70;
10537                 }
10538                 if(mainmenu)rotation+=multiplier*5;
10539       
10540                 //}
10541 }
10542
10543 void    Game::TickOnceAfter(){
10544         static XYZ colviewer;
10545         static XYZ coltarget;
10546         static XYZ target;
10547         static XYZ col;
10548         static float brotate;
10549         static XYZ facing;
10550         static int i,j;
10551         static float changedelay;
10552         static bool alldead;
10553         static float unseendelay;
10554         static float cameraspeed;
10555
10556         if(!mainmenu){
10557
10558                 if(environment==snowyenvironment)music1=stream_music1snow;
10559                 if(environment==grassyenvironment)music1=stream_music1grass;
10560                 if(environment==desertenvironment)music1=stream_music1desert;
10561
10562                 realthreat=0;
10563
10564                 musictype=music1;
10565                 for(i=0;i<numplayers;i++){
10566                         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)){
10567                                 musictype=stream_music2;
10568                                 realthreat=1;
10569                         }
10570                 }
10571                 if(player[0].dead)musictype=stream_music3;
10572
10573
10574                 if(musictype==stream_music2){
10575                         unseendelay=1;
10576                 }
10577
10578                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
10579                         unseendelay-=multiplier;
10580                         if(unseendelay>0){
10581                                 musictype=stream_music2;
10582                         }
10583                 }
10584
10585
10586                 if(loading==2){
10587                         musictype=stream_music3;
10588                         musicvolume[2]=512;
10589                         musicvolume[0]=0;
10590                         musicvolume[1]=0;
10591                         musicvolume[3]=0;
10592                 }
10593
10594                 if(musictoggle){
10595                         if(musictype!=oldmusictype&&musictype==stream_music2){
10596                                 static float gLoc[3];
10597                                 static float vel[3];
10598                                 gLoc[0]=cameraloc.x;
10599                                 gLoc[1]=cameraloc.y;
10600                                 gLoc[2]=cameraloc.z;
10601                                 vel[0]=0;
10602                                 vel[1]=0;
10603                                 vel[2]=0;
10604                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
10605                                 OPENAL_SetVolume(channels[alarmsound], 512);
10606                                 OPENAL_SetPaused(channels[alarmsound], false);
10607
10608                         }
10609                 }
10610                 musicselected=musictype;
10611
10612                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
10613                 else musicvolume[0]-=multiplier*450;
10614                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
10615                 else musicvolume[1]-=multiplier*450;
10616                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
10617                 else musicvolume[2]-=multiplier*450;
10618                 /*
10619                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
10620                 else musicvolume[0]-=multiplier*450;
10621                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
10622                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
10623                 else musicvolume[1]-=multiplier*100;
10624                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
10625                 else musicvolume[2]-=multiplier*450;*/
10626
10627                 for(i=0;i<3;i++){
10628                         if(musicvolume[i]<0)musicvolume[i]=0;
10629                         if(musicvolume[i]>512)musicvolume[i]=512;
10630                 }
10631
10632                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
10633
10634                 if(musictoggle){
10635                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
10636                                 PlayStreamEx( music1, strm[music1], NULL, true);
10637                                 OPENAL_SetPaused(channels[music1], false);
10638                         }
10639                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
10640                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
10641                                 OPENAL_SetPaused(channels[stream_music2], false);
10642                         }
10643                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
10644                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10645                                 OPENAL_SetPaused(channels[stream_music3], false);
10646                         }
10647                 }
10648
10649                 if(!musictoggle){
10650                         OPENAL_SetPaused(channels[music1], true);
10651                         OPENAL_SetPaused(channels[stream_music2], true);
10652                         OPENAL_SetPaused(channels[stream_music3], true);
10653
10654                         for(i=0;i<4;i++){
10655                                 oldmusicvolume[i]=0;
10656                                 musicvolume[i]=0;
10657                         }
10658                 }
10659
10660                 if(musictoggle){
10661                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
10662                                 OPENAL_SetPaused(channels[music1], true);
10663                         }
10664                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
10665                                 OPENAL_SetPaused(channels[stream_music2], true);
10666                         }
10667                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
10668                                 OPENAL_SetPaused(channels[stream_music3], true);
10669                         }
10670
10671                         if(musicvolume[0]!=oldmusicvolume[0]){
10672                                 OPENAL_SetVolume(channels[music1], musicvolume[0]);
10673                         }
10674                         if(musicvolume[1]!=oldmusicvolume[1]){
10675                                 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
10676                         }
10677                         if(musicvolume[2]!=oldmusicvolume[2]){
10678                                 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
10679                         }
10680
10681                         for(i=0;i<3;i++){
10682                                 oldmusicvolume[i]=musicvolume[i];
10683                         }
10684                 }
10685
10686                 killhotspot=2;
10687                 if(numhotspots)
10688                         for(i=0;i<numhotspots;i++){
10689                                 if(hotspottype[i]>10&&hotspottype[i]<20){
10690                                         if(player[hotspottype[i]-10].dead==0){
10691                                                 killhotspot=0;
10692                                         }
10693                                         else if(killhotspot==2)
10694                                                 killhotspot=1;
10695                                 }
10696                         }
10697                         if(killhotspot==2)killhotspot=0;
10698
10699
10700                         winhotspot=0;
10701                         if(numhotspots)
10702                                 for(i=0;i<numhotspots;i++){
10703                                         if(hotspottype[i]==-1){
10704                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
10705                                                         winhotspot=1;
10706                                         }
10707                                 }
10708
10709                                 int numalarmed=0;
10710                                 if(numplayers>1)
10711                                         for(i=1;i<numplayers;i++){
10712                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
10713                                         }
10714                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
10715
10716                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
10717                                                 if(player[0].dead&&changedelay<=0){
10718                                                         changedelay=1;
10719                                                         targetlevel=whichlevel;
10720                                                 }
10721                                                 alldead=1;
10722                                                 if(numplayers>1)
10723                                                         for(i=1;i<numplayers;i++){
10724                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
10725                                                         }
10726
10727
10728                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
10729                                                                 changedelay=1;
10730                                                                 targetlevel=whichlevel+1;
10731                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10732                                                         }
10733                                                         if(winhotspot||windialogue){
10734                                                                 changedelay=0.1;
10735                                                                 targetlevel=whichlevel+1;
10736                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10737                                                         }
10738
10739
10740                                                         if(killhotspot){
10741                                                                 changedelay=1;
10742                                                                 targetlevel=whichlevel+1;
10743                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10744                                                         }
10745
10746                                                         if(changedelay>0&&!player[0].dead&&!won){
10747                                                                 //high scores, awards, win
10748                                                                 if(campaign){
10749                                                                         won=1;
10750                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
10751                                                                         accountcampaignchoicesmade[accountactive]++;
10752                                                                         accountcampaignscore[accountactive]+=bonustotal;
10753                                                                         scoreadded=1;
10754                                                                         accountcampaigntime[accountactive]+=leveltime;
10755                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
10756
10757                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
10758                                                                 }
10759                                                                 else
10760                                                                 {
10761                                                                         won=1;
10762                                                                         if(!debugmode){
10763                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
10764                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;
10765                                                                         }
10766                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
10767
10768                                                                 }
10769                                                         }
10770                                         }
10771
10772                                         if(!winfreeze){
10773
10774                                                 if(leveltime<1){
10775                                                         loading=0;
10776                                                         changedelay=.1;
10777                                                         alldead=0;
10778                                                         winhotspot=0;
10779                                                         killhotspot=0;
10780                                                 }
10781
10782                                                 if(!editorenabled&&gameon&&!mainmenu){
10783                                                         if(changedelay!=-999)changedelay-=multiplier/7;
10784                                                         if(player[0].dead)targetlevel=whichlevel;
10785                                                         if(loading==2&&!campaign){
10786                                                                 flashr=1;
10787                                                                 flashg=0;
10788                                                                 flashb=0;
10789                                                                 flashamount=1;
10790                                                                 flashdelay=1;
10791                                                                 loadtime=0;
10792
10793                                                                 float gLoc[3]={0,0,0};
10794                                                                 float vel[3]={0,0,0};
10795                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10796                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10797                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10798                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
10799                                                                 OPENAL_SetPaused(channels[firestartsound], false);
10800                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10801
10802                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
10803                                                                         startbonustotal=bonustotal;
10804                                                                 }
10805                                                                 if(!player[0].dead)Loadlevel(targetlevel);
10806                                                                 if(player[0].dead)Loadlevel(whichlevel);
10807
10808                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10809                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10810                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10811                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10812                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10813                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10814
10815                                                                 loading=3;
10816                                                         }
10817                                                         if(loading==2&&targetlevel==whichlevel){
10818                                                                 flashr=1;
10819                                                                 flashg=0;
10820                                                                 flashb=0;
10821                                                                 flashamount=1;
10822                                                                 flashdelay=1;
10823                                                                 loadtime=0;
10824
10825                                                                 float gLoc[3]={0,0,0};
10826                                                                 float vel[3]={0,0,0};
10827                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10828                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10829                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10830                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
10831                                                                 OPENAL_SetPaused(channels[firestartsound], false);
10832                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10833
10834                                                                 for(i=0;i<255;i++){
10835                                                                         mapname[i]='\0';
10836                                                                 }
10837                                                                 mapname[0]=':';
10838                                                                 mapname[1]='D';
10839                                                                 mapname[2]='a';
10840                                                                 mapname[3]='t';
10841                                                                 mapname[4]='a';
10842                                                                 mapname[5]=':';
10843                                                                 mapname[6]='M';
10844                                                                 mapname[7]='a';
10845                                                                 mapname[8]='p';
10846                                                                 mapname[9]='s';
10847                                                                 mapname[10]=':';
10848                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
10849                                                                 Loadlevel(mapname);
10850
10851                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10852                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10853                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10854                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10855                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10856                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10857
10858                                                                 loading=3;
10859                                                         }
10860                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
10861                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
10862                         {
10863                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
10864                                                                                 winfreeze=1;
10865                                                                                 changedelay=-999;
10866                                                                         }
10867                                                                         if(player[0].dead)loading=1;
10868                                                                 }
10869                                                         }
10870                                                 }
10871
10872                                                 if(campaign)
10873                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
10874                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
10875                                                                         endgame=1;
10876                                                                 }
10877                                                         }
10878                                                         else if(mainmenu==0&&winfreeze){
10879                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
10880                                                                         stealthloading=1;
10881                                                                 else stealthloading=0;
10882
10883                                                                 if(!stealthloading){
10884                                                                         float gLoc[3]={0,0,0};
10885                                                                         float vel[3]={0,0,0};
10886                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10887                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10888                                                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10889                                                                         OPENAL_SetVolume(channels[firestartsound], 256);
10890                                                                         OPENAL_SetPaused(channels[firestartsound], false);
10891                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10892
10893                                                                         flashr=1;
10894                                                                         flashg=0;
10895                                                                         flashb=0;
10896                                                                         flashamount=1;
10897                                                                         flashdelay=1;
10898                                                                 }
10899
10900                                                                 startbonustotal=0;
10901
10902                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
10903                                                                 //campaignnumlevels=0;
10904                                                                 //accountcampaignchoicesmade[accountactive]=0;
10905                                                                 ipstream.ignore(256,':');
10906                                                                 ipstream >> campaignnumlevels;
10907                                                                 for(i=0;i<campaignnumlevels;i++){
10908                                                                         ipstream.ignore(256,':');
10909                                                                         ipstream.ignore(256,':');
10910                                                                         ipstream.ignore(256,' ');
10911                                                                         ipstream >> campaignmapname[i];
10912                                                                         ipstream.ignore(256,':');
10913                                                                         ipstream >> campaigndescription[i];
10914                                                                         for(j=0;j<256;j++){
10915                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
10916                                                                         }
10917                                                                         ipstream.ignore(256,':');
10918                                                                         ipstream >> campaignchoosenext[i];
10919                                                                         ipstream.ignore(256,':');
10920                                                                         ipstream >> campaignnumnext[i];
10921                                                                         if(campaignnumnext[i])
10922                                                                                 for(j=0;j<campaignnumnext[i];j++){
10923                                                                                         ipstream.ignore(256,':');
10924                                                                                         ipstream >> campaignnextlevel[i][j];
10925                                                                                         campaignnextlevel[i][j]-=1;
10926                                                                                 }
10927                                                                                 ipstream.ignore(256,':');
10928                                                                                 ipstream >> campaignlocationx[i];
10929                                                                                 ipstream.ignore(256,':');
10930                                                                                 ipstream >> campaignlocationy[i];
10931                                                                 }
10932                                                                 ipstream.close();
10933
10934                                                                 for(i=0;i<campaignnumlevels;i++){
10935                                                                         levelvisible[i]=0;
10936                                                                         levelhighlight[i]=0;
10937                                                                 }
10938
10939
10940                                                                 for(i=0;i<campaignnumlevels;i++){
10941                                                                         levelvisible[i]=0;
10942                                                                         levelhighlight[i]=0;
10943                                                                 }
10944
10945                                                                 levelorder[0]=0;
10946                                                                 levelvisible[0]=1;
10947                                                                 if(accountcampaignchoicesmade[accountactive])
10948                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
10949                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
10950                                                                                 levelvisible[levelorder[i+1]]=1;
10951                                                                         }
10952                                                                         int whichlevelstart;
10953                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
10954                                                                         if(whichlevelstart<0){
10955                                                                                 campaignchoicenum=1;
10956                                                                                 campaignchoicewhich[0]=0;
10957                                                                         }
10958                                                                         else
10959                                                                         {
10960                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
10961                                                                                 if(campaignchoicenum)
10962                                                                                         for(i=0;i<campaignchoicenum;i++){
10963                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
10964                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
10965                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
10966                                                                                         }
10967                                                                         }
10968
10969                                                                         loading=2;
10970                                                                         loadtime=0;
10971                                                                         targetlevel=7;
10972                                                                         //if(firstload)TickOnceAfter();
10973                                                                         if(!firstload)LoadStuff();
10974                                                                         //else {
10975                                                                         for(i=0;i<255;i++){
10976                                                                                 mapname[i]='\0';
10977                                                                         }
10978                                                                         mapname[0]=':';
10979                                                                         mapname[1]='D';
10980                                                                         mapname[2]='a';
10981                                                                         mapname[3]='t';
10982                                                                         mapname[4]='a';
10983                                                                         mapname[5]=':';
10984                                                                         mapname[6]='M';
10985                                                                         mapname[7]='a';
10986                                                                         mapname[8]='p';
10987                                                                         mapname[9]='s';
10988                                                                         mapname[10]=':';
10989
10990                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
10991                                                                         //accountcampaignchoicesmade[accountactive]++;
10992
10993
10994                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
10995                                                                         whichchoice=0;
10996                                                                         visibleloading=1;
10997                                                                         stillloading=1;
10998                                                                         Loadlevel(mapname);
10999                                                                         campaign=1;
11000                                                                         mainmenu=0;
11001                                                                         gameon=1;
11002                                                                         OPENAL_SetPaused(channels[stream_music3], true);
11003
11004                                                                         stealthloading=0;
11005                                                         }
11006
11007                                                         if(loading==3)loading=0;
11008
11009                                         }
11010
11011                                         oldmusictype=musictype;
11012         }
11013
11014         facing=0;
11015         facing.z=-1;
11016
11017         facing=DoRotation(facing,-rotation2,0,0);
11018         facing=DoRotation(facing,0,0-rotation,0);
11019         viewerfacing=facing;
11020
11021         brotate=0;
11022         if(!cameramode){
11023                 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;
11024                 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;
11025                 target.y+=.1;
11026                 if(player[0].skeleton.free){
11027                         for(i=0;i<player[0].skeleton.num_joints;i++){
11028                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
11029                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11030                         }
11031                         target.y+=.1;
11032                 }
11033                 if(player[0].skeleton.free!=2&&!autocam){
11034                         cameraspeed=20;
11035                         if(findLengthfast(&player[0].velocity)>400){
11036                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11037                         }
11038                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11039                         coltarget=target-cameraloc;
11040                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11041                         else {
11042                                 Normalise(&coltarget);
11043                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11044                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11045                         }
11046                         if(editorenabled)cameraloc=target;
11047                         cameradist+=multiplier*5;
11048                         if(cameradist>2.3)cameradist=2.3;
11049                         viewer=cameraloc-facing*cameradist;
11050                         colviewer=viewer;
11051                         coltarget=cameraloc;
11052                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11053                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11054                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11055                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11056                                         colviewer=viewer;
11057                                         coltarget=cameraloc;
11058                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11059                                 }
11060                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11061                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11062                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11063                                                 colviewer=viewer;
11064                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11065                                                         viewer=colviewer;
11066                                                 }
11067                                         }
11068                                         cameradist=findDistance(&viewer,&target);
11069                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11070                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11071                                         }
11072                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11073                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11074                                         }
11075                 }
11076                 if(player[0].skeleton.free!=2&&autocam){
11077                         cameraspeed=20;
11078                         if(findLengthfast(&player[0].velocity)>400){
11079                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11080                         }
11081                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11082                         cameradist+=multiplier*5;
11083                         if(cameradist>3.3)cameradist=3.3;
11084                         coltarget=target-cameraloc;
11085                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11086                         else if(findLengthfast(&coltarget)>1)
11087                         {
11088                                 Normalise(&coltarget);
11089                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11090                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11091                         }
11092                         if(editorenabled)cameraloc=target;
11093                         viewer=cameraloc;
11094                         colviewer=viewer;
11095                         coltarget=cameraloc;
11096                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11097                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11098                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11099                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11100                                         colviewer=viewer;
11101                                         coltarget=cameraloc;
11102                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11103                                 }
11104                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11105                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11106                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11107                                                 colviewer=viewer;
11108                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11109                                                         viewer=colviewer;
11110                                                 }
11111                                         }
11112                                         cameradist=findDistance(&viewer,&target);
11113                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11114                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11115                                         }
11116                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11117                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11118                                         }
11119                 }
11120                 if(camerashake>.8)camerashake=.8;
11121                 //if(woozy>10)woozy=10;
11122                 //woozy+=multiplier;
11123                 woozy+=multiplier;
11124                 if(player[0].dead)camerashake=0;
11125                 if(player[0].dead)woozy=0;
11126                 camerashake-=multiplier*2;
11127                 blackout-=multiplier*2;
11128                 //if(player[0].isCrouch())woozy-=multiplier*8;
11129                 if(camerashake<0)camerashake=0;
11130                 if(blackout<0)blackout=0;
11131                 //if(woozy<0)woozy=0;
11132                 if(camerashake){
11133                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11134                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11135                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11136                 }
11137         }
11138 }