]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
Merged with parent
[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 texttoggle;
104 extern bool alwaysblur;
105 extern float gamespeed;
106 extern bool decals;
107 extern bool vblsync;
108 extern bool immediate;
109 extern bool velocityblur;
110 extern int bonus;
111 extern int oldbonus;
112 extern float bonusvalue;
113 extern float bonustotal;
114 extern float bonustime;
115 extern float startbonustotal;
116 extern float tintr,tintg,tintb;
117 extern float bonusnum[100];
118 extern bool skyboxtexture;
119 extern float skyboxr;
120 extern float skyboxg;
121 extern float skyboxb;
122 extern float skyboxlightr;
123 extern float skyboxlightg;
124 extern float skyboxlightb;
125 extern float fadestart;
126 extern float slomospeed;
127 extern float slomofreq;
128 extern int tutoriallevel;
129 extern float smoketex;
130 extern float tutorialstagetime;
131 extern int tutorialstage;
132 extern float tutorialmaxtime;
133 extern float tutorialsuccess;
134 extern bool againbonus;
135 extern bool reversaltrain;
136 extern bool canattack;
137 extern bool cananger;
138 extern float damagedealt;
139 extern float damagetaken;
140 extern int maptype;
141 extern int editoractive;
142 extern int editorpathtype;
143 extern bool oldbuttons[3];
144
145 extern float hostiletime;
146
147 extern bool gamestarted;
148
149 extern int numhotspots;
150 extern int winhotspot;
151 extern int windialogue;
152 extern int killhotspot;
153 extern XYZ hotspot[40];
154 extern int hotspottype[40];
155 extern float hotspotsize[40];
156 extern char hotspottext[40][256];
157 extern int currenthotspot;
158
159 extern int kBitsPerPixel;
160 extern int hostile;
161
162 extern int numaccounts;
163 extern int accountactive;
164 extern int accountdifficulty[10];
165 extern int accountprogress[10];
166 extern float accountpoints[10];
167 extern float accounthighscore[10][50];
168 extern float accountfasttime[10][50];
169 extern bool accountunlocked[10][60];
170 extern char accountname[10][256];
171
172 extern bool stillloading;
173 extern bool winfreeze;
174
175 extern int numfalls;
176 extern int numflipfail;
177 extern int numseen;
178 extern int numstaffattack;
179 extern int numswordattack;
180 extern int numknifeattack;
181 extern int numunarmedattack;
182 extern int numescaped;
183 extern int numflipped;
184 extern int numwallflipped;
185 extern int numthrowkill;
186 extern int numafterkill;
187 extern int numreversals;
188 extern int numattacks;
189 extern int maxalarmed;
190 extern int numresponded;
191
192 extern int numdialogues;
193 extern int numdialogueboxes[max_dialogues];
194 extern int dialoguetype[max_dialogues];
195 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
196 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
197 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
198 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
199 extern char dialoguename[max_dialogues][max_dialoguelength][64];
200 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
201 extern XYZ participantlocation[max_dialogues][10];
202 extern int participantfocus[max_dialogues][max_dialoguelength];
203 extern int participantaction[max_dialogues][max_dialoguelength];
204 extern float participantrotation[max_dialogues][10];
205 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
206 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
207 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
208 extern int indialogue;
209 extern int whichdialogue;
210 extern int directing;
211 extern float dialoguetime;
212 extern int dialoguegonethrough[20];
213
214 extern bool campaign;
215
216 extern float oldgamespeed;
217
218 extern float accountcampaignhighscore[10];
219 extern float accountcampaignfasttime[10];
220 extern float accountcampaignscore[10];
221 extern float accountcampaigntime[10];
222
223 extern int accountcampaignchoicesmade[10];
224 extern int accountcampaignchoices[10][5000];
225
226 static const char *rabbitskin[] = {
227 ":Data:Textures:Fur3.jpg",
228 ":Data:Textures:Fur.jpg",
229 ":Data:Textures:Fur2.jpg",
230 ":Data:Textures:Lynx.jpg",
231 ":Data:Textures:Otter.jpg",
232 ":Data:Textures:Opal.jpg",
233 ":Data:Textures:Sable.jpg",
234 ":Data:Textures:Chocolate.jpg",
235 ":Data:Textures:BW2.jpg",
236 ":Data:Textures:WB2.jpg"
237 };
238
239 static const char *wolfskin[] = {
240 ":Data:Textures:Wolf.jpg",
241 ":Data:Textures:Darkwolf.jpg",
242 ":Data:Textures:Snowwolf.jpg"
243 };
244
245 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
246 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
247
248 static const char **creatureskin[] = {rabbitskin, wolfskin};
249
250 /********************> Tick() <*****/
251 extern OPENAL_STREAM * strm[20];
252 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
253 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
254
255 extern void ScreenShot(const char * fname);
256 void Screenshot (void)
257 {
258         char temp[1024];
259         time_t  t = time(NULL);
260         struct  tm *tme = localtime(&t);
261         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);
262
263         #if defined(_WIN32)
264         mkdir("Screenshots");
265         #else
266         mkdir("Screenshots", S_IRWXU);
267         #endif
268
269         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
270
271         /*FSSpec                                MAC_file;
272         GraphicsExportComponent QT_exporter;
273         OSErr                           MAC_error_code;
274         CGrafPtr                        MAC_currentPort;
275         GDHandle                        MAC_currentDevice;
276         unsigned char*          MAC_pixels;
277         Rect                            MAC_picture_rectangle;
278         GWorldPtr                       MAC_offscreen_graphics_port;
279
280         static int numscreenshots=0;
281
282         // Make an FSSpec
283         static char buf[256];
284         if(numscreenshots==0){
285         buf[0]=26;
286         buf[1]=':';
287         buf[2]='S';
288         buf[3]='c';
289         buf[4]='r';
290         buf[5]='e';
291         buf[6]='e';
292         buf[7]='n';
293         buf[8]='s';
294         buf[9]='h';
295         buf[10]='o';
296         buf[11]='t';
297         buf[12]='s';
298         buf[13]=':';
299         buf[14]='S';
300         buf[15]='c';
301         buf[16]='r';
302         buf[17]='e';
303         buf[18]='e';
304         buf[19]='n';
305         buf[20]='s';
306         buf[21]='h';
307         buf[22]='o';
308         buf[23]='t';
309         buf[24]='0';
310         buf[25]='0';
311         buf[26]='0';
312         }
313
314         FInfo *fndrInfo;
315         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
316         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
317         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
318         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
319         numscreenshots++;
320         buf[26]++;
321         if(buf[26]==':'){
322         buf[26]='0';
323         buf[25]++;
324         if(buf[25]==':'){
325         buf[25]='0';
326         buf[24]++;
327         if(buf[24]==':'){
328         buf[24]='9';
329         buf[25]='9';
330         buf[26]='9';
331         }
332         }
333         }
334         }
335         }
336
337
338         // Get the GWorld
339         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
340         //assert(MAC_gWorld != NULL);
341
342         // Allocate memory for loading image
343         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
344         if (MAC_pixels == NULL) {
345         //UTIL_Error("Could not create Texture data.");
346         return;
347         }
348
349         // Get GWorld
350         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
351
352         // Make a picture Rectangle
353         MAC_picture_rectangle.left = 0;
354         MAC_picture_rectangle.right = screenwidth;
355         MAC_picture_rectangle.top = 0;
356         MAC_picture_rectangle.bottom = screenheight;
357
358         // Create new offscreen GWorld
359         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
360         if (MAC_error_code)     {
361         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
362         delete MAC_pixels;
363         //UTIL_Error("Could not create offscreen GWorld. ");
364         return;
365
366         }
367
368         // Copy OpenGL Context to new GWorld
369         glReadBuffer(GL_FRONT);
370         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
371
372         // Swizzle texture
373         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
374         unsigned char temp = MAC_pixels[byte+0];
375         MAC_pixels[byte+0] = MAC_pixels[byte+3];
376         MAC_pixels[byte+3] = MAC_pixels[byte+2];
377         MAC_pixels[byte+2] = MAC_pixels[byte+1];
378         MAC_pixels[byte+1] = temp;
379         }
380
381         // Flip the image  :(   This could probably be optimized
382         int vert;
383         int src_index;
384         int dst_index;
385         unsigned char temp;
386         for (int horz = 0; horz < screenwidth; ++horz)
387         for (vert = 0; vert < screenheight / 2; ++vert) {
388         src_index = (screenwidth * vert + horz) * 4;
389         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
390
391         temp=MAC_pixels[src_index+0];
392         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
393         MAC_pixels[dst_index+0]=temp;
394
395         temp=MAC_pixels[src_index+1];
396         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
397         MAC_pixels[dst_index+1]=temp;
398
399         temp=MAC_pixels[src_index+2];
400         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
401         MAC_pixels[dst_index+2]=temp;
402
403         temp=MAC_pixels[src_index+3];
404         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
405         MAC_pixels[dst_index+3]=temp;
406         }
407
408
409
410         // Export the Gworld
411         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
412         if (MAC_error_code) {
413         //UTIL_Warning("Unable to export screenshot.");
414         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
415         ::DisposeGWorld(MAC_offscreen_graphics_port);
416         delete MAC_pixels;
417         return;
418         }
419
420         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
421         if (MAC_error_code) {
422         ::CloseComponent(QT_exporter);
423         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
424         ::DisposeGWorld(MAC_offscreen_graphics_port);
425         delete MAC_pixels;
426         //UTIL_Warning("Unable to export screenshot.");
427         return;
428         }
429
430         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
431         if (MAC_error_code) {
432         ::CloseComponent(QT_exporter);
433         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
434         ::DisposeGWorld(MAC_offscreen_graphics_port);
435         delete MAC_pixels;
436         //UTIL_Warning("Unable to export screenshot.");
437         return;
438         }
439
440         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
441         if (MAC_error_code) {
442         ::CloseComponent(QT_exporter);
443         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
444         ::DisposeGWorld(MAC_offscreen_graphics_port);
445         delete MAC_pixels;
446         //UTIL_Warning("Unable to export screenshot.");
447         return;
448         }
449
450         ::CloseComponent(QT_exporter);
451         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
452         ::DisposeGWorld(MAC_offscreen_graphics_port);
453
454         delete MAC_pixels;*/
455 }
456
457
458
459 void    Game::SetUpLighting(){
460         if(environment==snowyenvironment){
461                 light.color[0]=.65;
462                 light.color[1]=.65;
463                 light.color[2]=.7;
464                 light.ambient[0]=.4;
465                 light.ambient[1]=.4;
466                 light.ambient[2]=.44;
467         }
468         if(environment==desertenvironment){
469                 light.color[0]=.95;
470                 light.color[1]=.95;
471                 light.color[2]=.95;
472                 light.ambient[0]=.4;
473                 light.ambient[1]=.35;
474                 light.ambient[2]=.3;
475         }
476
477         if(environment==grassyenvironment){
478                 light.color[0]=.95;
479                 light.color[1]=.95;
480                 light.color[2]=1;
481                 light.ambient[0]=.4;
482                 light.ambient[1]=.4;
483                 light.ambient[2]=.44;
484         }
485         if(!skyboxtexture){
486                 light.color[0]=1;
487                 light.color[1]=1;
488                 light.color[2]=1;
489                 light.ambient[0]=.4;
490                 light.ambient[1]=.4;
491                 light.ambient[2]=.4;
492         }
493         float average;
494         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
495         light.color[0]*=(skyboxlightr+average)/2;
496         light.color[1]*=(skyboxlightg+average)/2;
497         light.color[2]*=(skyboxlightb+average)/2;
498         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
499         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
500         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
501         /*
502         light.ambient[0]=0;
503         light.ambient[1]=0;
504         light.ambient[2]=0;     */
505 }
506
507 int Game::findPathDist(int start,int end){
508         int i,j,k,smallestcount,count,connected;
509         int last,last2,last3,last4;
510         int closest;
511
512         smallestcount=1000;
513         for(i=0;i<50;i++){
514                 count=0;
515                 last=start;
516                 last2=-1;
517                 last3=-1;
518                 last4=-1;
519                 while(last!=end&&count<30){
520                         closest=-1;
521                         for(j=0;j<numpathpoints;j++){
522                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
523                                 {
524                                         connected=0;
525                                         if(numpathpointconnect[j])
526                                                 for(k=0;k<numpathpointconnect[j];k++){
527                                                         if(pathpointconnect[j][k]==last)connected=1;
528                                                 }
529                                                 if(!connected)
530                                                         if(numpathpointconnect[last])
531                                                                 for(k=0;k<numpathpointconnect[last];k++){
532                                                                         if(pathpointconnect[last][k]==j)connected=1;
533                                                                 }
534                                                                 if(connected)
535                                                                         if(closest==-1||Random()%2==0){
536                                                                                 closest=j;
537                                                                         }
538                                 }
539                         }
540                         last4=last3;
541                         last3=last2;
542                         last2=last;
543                         last=closest;
544                         count++;
545                 }
546                 if(count<smallestcount)smallestcount=count;
547         }
548         return smallestcount;
549 }
550
551 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
552         static XYZ colpoint,colviewer,coltarget;
553         static float minx,minz,maxx,maxz,miny,maxy;
554         static int i;
555
556         //startpoint.y+=.7;
557         //endpoint.y+=.7;
558         //startpoint.y-=.1;
559         //endpoint.y-=.1;
560
561         minx=startpoint.x;
562         if(minx>endpoint.x)minx=endpoint.x;
563         miny=startpoint.y;
564         if(miny>endpoint.y)miny=endpoint.y;
565         minz=startpoint.z;
566         if(minz>endpoint.z)minz=endpoint.z;
567
568         maxx=startpoint.x;
569         if(maxx<endpoint.x)maxx=endpoint.x;
570         maxy=startpoint.y;
571         if(maxy<endpoint.y)maxy=endpoint.y;
572         maxz=startpoint.z;
573         if(maxz<endpoint.z)maxz=endpoint.z;
574
575         minx-=1;
576         miny-=1;
577         minz-=1;
578         maxx+=1;
579         maxy+=1;
580         maxz+=1;
581
582         for(i=0;i<objects.numobjects;i++){
583                 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){
584                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
585                                 colviewer=startpoint;
586                                 coltarget=endpoint;
587                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
588                         }
589                 }
590         }
591
592         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
593
594         return -1;
595 }
596
597 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
598         static XYZ colpoint,colviewer,coltarget;
599         static float minx,minz,maxx,maxz,miny,maxy;
600         static int i;
601
602         //startpoint.y+=.7;
603         //endpoint.y+=.7;
604         //startpoint.y-=.1;
605         //endpoint.y-=.1;
606
607         minx=startpoint.x;
608         if(minx>endpoint.x)minx=endpoint.x;
609         miny=startpoint.y;
610         if(miny>endpoint.y)miny=endpoint.y;
611         minz=startpoint.z;
612         if(minz>endpoint.z)minz=endpoint.z;
613
614         maxx=startpoint.x;
615         if(maxx<endpoint.x)maxx=endpoint.x;
616         maxy=startpoint.y;
617         if(maxy<endpoint.y)maxy=endpoint.y;
618         maxz=startpoint.z;
619         if(maxz<endpoint.z)maxz=endpoint.z;
620
621         minx-=1;
622         miny-=1;
623         minz-=1;
624         maxx+=1;
625         maxy+=1;
626         maxz+=1;
627
628         if(what!=1000){
629                 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){
630                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
631                                 colviewer=startpoint;
632                                 coltarget=endpoint;
633                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
634                         }
635                 }
636         }
637
638         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
639
640         return -1;
641 }
642
643 void    Game::Setenvironment(int which)
644 {
645         LOGFUNC;
646
647         LOG(" Setting environment...");
648
649         float temptexdetail;
650         environment=which;
651 /*
652         OPENAL_SetPaused(channels[music1snow], true);
653         OPENAL_SetPaused(channels[music1grass], true);
654         OPENAL_SetPaused(channels[music1desert], true);
655         OPENAL_SetPaused(channels[wind], true);
656         OPENAL_SetPaused(channels[desertambient], true);
657 */
658         OPENAL_SetPaused(channels[stream_music1snow], true);
659         OPENAL_SetPaused(channels[stream_music1grass], true);
660         OPENAL_SetPaused(channels[stream_music1desert], true);
661         OPENAL_SetPaused(channels[stream_wind], true);
662         OPENAL_SetPaused(channels[stream_desertambient], true);
663
664
665         if(environment==snowyenvironment){
666                 windvector=0;
667                 windvector.z=3;
668                 if(ambientsound){
669                         //PlaySoundEx( wind, samp[wind], NULL, true);
670                         PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
671                         OPENAL_SetPaused(channels[stream_wind], false);
672                         OPENAL_SetVolume(channels[stream_wind], 256);
673                 }
674
675                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
676                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
677                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
678                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
679
680                 OPENAL_Sample_Free(samp[footstepsound]);
681                 OPENAL_Sample_Free(samp[footstepsound2]);
682                 OPENAL_Sample_Free(samp[footstepsound3]);
683                 OPENAL_Sample_Free(samp[footstepsound4]);
684                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
685                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
686                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
687                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
688                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
689                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
690                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
691                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
692
693                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
694
695                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
696
697                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
698
699
700
701
702                 temptexdetail=texdetail;
703                 if(texdetail>1)texdetail=4;
704                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
705                         ":Data:Textures:Skybox(snow):Left.jpg",
706                         ":Data:Textures:Skybox(snow):Back.jpg",
707                         ":Data:Textures:Skybox(snow):Right.jpg",
708                         ":Data:Textures:Skybox(snow):Up.jpg",
709                         ":Data:Textures:Skybox(snow):Down.jpg",
710                         ":Data:Textures:Skybox(snow):Cloud.jpg",
711                         ":Data:Textures:Skybox(snow):Reflect.jpg");
712
713
714
715
716                 texdetail=temptexdetail;
717         }
718         if(environment==desertenvironment){
719                 windvector=0;
720                 windvector.z=2;
721                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
722                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
723                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
724                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
725
726
727                 if(ambientsound){
728                         //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
729                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
730                         OPENAL_SetPaused(channels[stream_desertambient], false);
731                         OPENAL_SetVolume(channels[stream_desertambient], 256);
732                 }
733
734                 OPENAL_Sample_Free(samp[footstepsound]);
735                 OPENAL_Sample_Free(samp[footstepsound2]);
736                 OPENAL_Sample_Free(samp[footstepsound3]);
737                 OPENAL_Sample_Free(samp[footstepsound4]);
738                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
739                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
740                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
741                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
742                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
743                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
744                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
745                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
746
747                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
748
749                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
750
751                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
752
753
754
755                 temptexdetail=texdetail;
756                 if(texdetail>1)texdetail=4;
757                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
758                         ":Data:Textures:Skybox(sand):Left.jpg",
759                         ":Data:Textures:Skybox(sand):Back.jpg",
760                         ":Data:Textures:Skybox(sand):Right.jpg",
761                         ":Data:Textures:Skybox(sand):Up.jpg",
762                         ":Data:Textures:Skybox(sand):Down.jpg",
763                         ":Data:Textures:Skybox(sand):Cloud.jpg",
764                         ":Data:Textures:Skybox(sand):Reflect.jpg");
765
766
767
768
769                 texdetail=temptexdetail;
770         }
771         if(environment==grassyenvironment){
772                 windvector=0;
773                 windvector.z=2;
774                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
775                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
776                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
777                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
778
779                 if(ambientsound){
780                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
781                         OPENAL_SetPaused(channels[stream_wind], false);
782                         OPENAL_SetVolume(channels[stream_wind], 100);
783                 }
784
785                 OPENAL_Sample_Free(samp[footstepsound]);
786                 OPENAL_Sample_Free(samp[footstepsound2]);
787                 OPENAL_Sample_Free(samp[footstepsound3]);
788                 OPENAL_Sample_Free(samp[footstepsound4]);
789                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass1.ogg"), OPENAL_HW3D, 0, 0);
790                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass2.ogg"), OPENAL_HW3D, 0, 0);
791                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
792                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
793                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
794                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
795                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
796                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
797
798                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
799
800                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
801
802                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
803
804
805
806                 temptexdetail=texdetail;
807                 if(texdetail>1)texdetail=4;
808                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
809                         ":Data:Textures:Skybox(grass):Left.jpg",
810                         ":Data:Textures:Skybox(grass):Back.jpg",
811                         ":Data:Textures:Skybox(grass):Right.jpg",
812                         ":Data:Textures:Skybox(grass):Up.jpg",
813                         ":Data:Textures:Skybox(grass):Down.jpg",
814                         ":Data:Textures:Skybox(grass):Cloud.jpg",
815                         ":Data:Textures:Skybox(grass):Reflect.jpg");
816
817
818
819                 texdetail=temptexdetail;
820         }
821         temptexdetail=texdetail;
822         texdetail=1;
823         terrain.load(":Data:Textures:heightmap.png");
824
825         texdetail=temptexdetail;
826 }
827
828
829 void    Game::Loadlevel(int which){
830         stealthloading=0;
831
832         if(which==0)Loadlevel((char *)":Data:Maps:map1");
833         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
834         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
835         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
836         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
837         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
838         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
839         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
840         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
841         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
842         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
843         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
844         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
845         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
846         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
847         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
848         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
849         else Loadlevel((char *)":Data:Maps:mapsave");
850
851         whichlevel=which;
852 }
853
854 /*char * Game::MD5_string (unsigned char *string){
855 char temp[50];
856 char temp2[100];
857
858 strcpy(temp2,(const char *)string);
859 strcat((char *)temp2,(const char *)"Lugaru");
860 sprintf (temp, "%d",strlen((char *)temp2));
861 strcat((char *)temp2,temp);
862
863 MD5 context;
864 unsigned int len = strlen ( (char *)temp2);
865
866 context.update   ((unsigned char *)temp2, len);
867 context.finalize ();
868
869 return context.hex_digest();
870 }*/
871
872
873
874 void    Game::Loadlevel(char *name){
875         int i,j,k,l,m;
876         static int oldlevel;
877         int templength;
878         float lamefloat;
879         int lameint;
880
881         float headprop,legprop,armprop,bodyprop;
882
883         LOGFUNC;
884
885         LOG(std::string("Loading level...") + name);
886
887         if(!gameon)visibleloading=1;
888
889         if(stealthloading)visibleloading=0;
890
891         if(!stillloading)loadtime=0;
892         gamestarted=1;
893
894         numenvsounds=0;
895         //visibleloading=1;
896         if(tutoriallevel!=-1)tutoriallevel=0;
897         else tutoriallevel=1;
898
899         if(tutoriallevel==1)tutorialstage=0;
900         if(tutorialstage==0){
901                 tutorialstagetime=0;
902                 tutorialmaxtime=1;
903         }
904         loadingstuff=1;
905         if(!firstload){
906                 oldlevel=50;
907         }
908         OPENAL_SetPaused(channels[whooshsound], true);
909         OPENAL_SetPaused(channels[stream_firesound], true);
910
911         // Change the map filename into something that is os specific
912         char *FixedFN = ConvertFileName(name);
913
914         int mapvers;
915         FILE                    *tfile;
916         tfile=fopen( FixedFN, "rb" );
917         if(tfile)
918         {
919                 OPENAL_SetPaused(channels[stream_firesound], true);
920
921
922                 scoreadded=0;
923                 windialogue=0;
924
925                 hostiletime=0;
926
927                 won=0;
928
929                 //campaign=0;
930                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
931
932                 numdialogues=0;
933
934                 for(i=0;i<20;i++)
935                 {
936                         dialoguegonethrough[i]=0;
937                 }
938
939                 indialogue=-1;
940                 cameramode=0;
941
942                 damagedealt=0;
943                 damagetaken=0;
944
945                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
946
947                 if(difficulty!=2)minimap=1;
948                 else minimap=0;
949
950                 numhotspots=0;
951                 currenthotspot=-1;
952                 bonustime=1;
953
954                 skyboxtexture=1;
955                 skyboxr=1;
956                 skyboxg=1;
957                 skyboxb=1;
958
959                 freeze=0;
960                 winfreeze=0;
961
962                 for(i=0;i<100;i++)
963                 {
964                         bonusnum[i]=0;
965                 }
966
967                 numfalls=0;
968                 numflipfail=0;
969                 numseen=0;
970                 numstaffattack=0;
971                 numswordattack=0;
972                 numknifeattack=0;
973                 numunarmedattack=0;
974                 numescaped=0;
975                 numflipped=0;
976                 numwallflipped=0;
977                 numthrowkill=0;
978                 numafterkill=0;
979                 numreversals=0;
980                 numattacks=0;
981                 maxalarmed=0;
982                 numresponded=0;
983
984                 bonustotal=startbonustotal;
985                 bonus=0;
986                 gameon=1;
987                 changedelay=0;
988                 if(console)
989                 {
990                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
991                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
992                         OPENAL_SetPaused(channels[consolesuccesssound], false);
993                         freeze=0;
994                         console=0;
995                 }
996
997                 if(!stealthloading)
998                 {
999                         terrain.numdecals=0;
1000                         sprites.numsprites=0;
1001                         for(i=0;i<objects.numobjects;i++)
1002                         {
1003                                 objects.model[i].numdecals=0;
1004                         }
1005
1006                         j=objects.numobjects;
1007                         for(i=0;i<j;i++)
1008                         {
1009                                 objects.DeleteObject(0);
1010                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1011                         }
1012
1013                         for(i=0;i<subdivision;i++)
1014                         {
1015                                 for(j=0;j<subdivision;j++)
1016                                 {
1017                                         terrain.patchobjectnum[i][j]=0;
1018                                 }
1019                         }
1020                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1021                 }
1022
1023                 weapons.numweapons=0;
1024
1025                 funpackf(tfile, "Bi", &mapvers);
1026                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
1027                 else indemo=0;
1028                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1029                 else maptype=mapkilleveryone;
1030                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1031                 else hostile=1;
1032                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1033                 else
1034                 {
1035                         viewdistance=100;
1036                         fadestart=.6;
1037                 }
1038                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1039                 else
1040                 {
1041                         skyboxtexture=1;
1042                         skyboxr=1;
1043                         skyboxg=1;
1044                         skyboxb=1;
1045                 }
1046                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1047                 else
1048                 {
1049                         skyboxlightr=skyboxr;
1050                         skyboxlightg=skyboxg;
1051                         skyboxlightb=skyboxb;
1052                 }
1053                 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);
1054                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1055                 player[0].originalcoords=player[0].coords;
1056                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1057                 {
1058                         for(j=0;j<player[0].num_weapons;j++)
1059                         {
1060                                 player[0].weaponids[j]=weapons.numweapons;
1061                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1062                                 weapons.owner[weapons.numweapons]=0;
1063                                 weapons.numweapons++;
1064                         }
1065                 }
1066
1067                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1068
1069                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1070                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1071                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1072                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1073
1074                 funpackf(tfile, "Bi", &player[0].numclothes);
1075
1076                 if(mapvers>=9)
1077                 {
1078                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1079                 }
1080                 else
1081                 {
1082                         player[0].whichskin=0;
1083                         player[0].creature=rabbittype;
1084                 }
1085
1086                 for(i=0;i<max_dialogues;i++)
1087                 {
1088                         for(j=0;j<max_dialoguelength;j++)
1089                         {
1090                                 for(k=0;k<128;k++)
1091                                 {
1092                                         dialoguetext[i][j][k]='\0';
1093                                 }
1094                                 for(k=0;k<64;k++)
1095                                 {
1096                                         dialoguename[i][j][k]='\0';
1097                                 }
1098                         }
1099                 }
1100
1101                 player[0].lastattack=-1;
1102                 player[0].lastattack2=-1;
1103                 player[0].lastattack3=-1;
1104
1105                 if(mapvers>=8)
1106                 {
1107                         funpackf(tfile, "Bi", &numdialogues);
1108                         if(numdialogues)
1109                         {
1110                                 for(k=0;k<numdialogues;k++)
1111                                 {
1112                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1113                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1114                                         for(l=0;l<10;l++)
1115                                         {
1116                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1117                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1118                                         }
1119                                         if(numdialogueboxes)
1120                                         {
1121                                                 for(l=0;l<numdialogueboxes[k];l++)
1122                                                 {
1123                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1124                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1125                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1126                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1127                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1128
1129                                                         bool doneread;
1130
1131                                                         funpackf(tfile, "Bi",&templength);
1132                                                         if(templength>128||templength<=0)templength=128;
1133                                                         for(m=0;m<templength;m++){
1134                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1135                                                                 if(dialoguetext[k][l][m]=='\0')break;
1136                                                         }
1137
1138                                                         funpackf(tfile, "Bi",&templength);
1139                                                         if(templength>64||templength<=0)templength=64;
1140                                                         for(m=0;m<templength;m++){
1141                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1142                                                                 if(dialoguename[k][l][m]=='\0'){
1143                                                                         break;
1144                                                                 }
1145                                                         }
1146                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1147                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1148                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1149
1150                                                         for(m=0;m<10;m++)
1151                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1152
1153                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1154                                                 }
1155                                         }
1156                                 }
1157                         }
1158                 }
1159                 else numdialogues=0;
1160
1161                 if(player[0].numclothes)
1162                 {
1163                         for(k=0;k<player[0].numclothes;k++)
1164                         {
1165                                 funpackf(tfile, "Bi", &templength);
1166                                 for(l=0;l<templength;l++)
1167                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1168                                 player[0].clothes[k][templength]='\0';
1169                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1170                         }
1171                 }
1172
1173                 funpackf(tfile, "Bi", &environment);
1174
1175                 funpackf(tfile, "Bi", &objects.numobjects);
1176                 if(objects.numobjects)
1177                 {
1178                         for(i=0;i<objects.numobjects;i++)
1179                         {
1180                                 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]);
1181                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1182                         }
1183                 }
1184
1185                 if(mapvers>=7)
1186                 {
1187                         funpackf(tfile, "Bi", &numhotspots);
1188                         if(numhotspots)
1189                         {
1190                                 for(i=0;i<numhotspots;i++)
1191                                 {
1192                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1193                                         funpackf(tfile, "Bi", &templength);
1194                                         if(templength)
1195                                                 for(l=0;l<templength;l++)
1196                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1197                                         hotspottext[i][templength]='\0';
1198                                         if(hotspottype[i]==-111)indemo=1;
1199                                 }
1200                         }
1201                 }
1202                 else numhotspots=0;
1203
1204                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1205
1206                 if(!stealthloading)
1207                 {
1208                         objects.center=0;
1209                         for(i=0;i<objects.numobjects;i++)
1210                         {
1211                                 objects.center+=objects.position[i];
1212                         }
1213                         objects.center/=objects.numobjects;
1214
1215
1216                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1217
1218                         float maxdistance=0;
1219                         float tempdist;
1220                         int whichclosest;
1221                         for(i=0;i<objects.numobjects;i++)
1222                         {
1223                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1224                                 if(tempdist>maxdistance)
1225                                 {
1226                                         whichclosest=i;
1227                                         maxdistance=tempdist;
1228                                 }
1229                         }
1230                         objects.radius=fast_sqrt(maxdistance);
1231                 }
1232
1233                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1234                 //mapcenter=objects.center;
1235                 //mapradius=objects.radius;
1236
1237                 funpackf(tfile, "Bi", &numplayers);
1238                 int howmanyremoved=0;
1239                 bool removeanother=0;
1240                 if(numplayers>1&&numplayers<maxplayers)
1241                 {
1242                         for(i=1;i<numplayers;i++)
1243                         {
1244                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1245                                 removeanother=0;
1246
1247                                 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);
1248                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1249                                 else player[i-howmanyremoved].howactive=typeactive;
1250                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1251                                 else player[i-howmanyremoved].scale=-1;
1252                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1253                                 else player[i-howmanyremoved].immobile=0;
1254                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1255                                 else player[i-howmanyremoved].rotation=0;
1256                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1257                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1258                                         removeanother=1;
1259                                         howmanyremoved++;
1260                                 }
1261                                 if(!removeanother)
1262                                 {
1263                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1264                                         {
1265                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1266                                                 {
1267                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1268                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1269                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1270                                                         weapons.numweapons++;
1271                                                 }
1272                                         }
1273                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1274                                         //player[i-howmanyremoved].numwaypoints=10;
1275                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1276                                         {
1277                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1278                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1279                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1280                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1281                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1282                                         }
1283
1284                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1285                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1286
1287                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1288                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1289                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1290                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1291
1292                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1293                                         else
1294                                         {
1295                                                 headprop=1;
1296                                                 bodyprop=1;
1297                                                 armprop=1;
1298                                                 legprop=1;
1299                                         }
1300                                         if(player[i-howmanyremoved].creature==wolftype)
1301                                         {
1302                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1303                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1304                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1305                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1306                                         }
1307
1308                                         if(player[i-howmanyremoved].creature==rabbittype)
1309                                         {
1310                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1311                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1312                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1313                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1314                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1315                                         }
1316
1317                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1318                                         if(player[i-howmanyremoved].numclothes)
1319                                         {
1320                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1321                                                 {
1322                                                         int templength;
1323                                                         funpackf(tfile, "Bi", &templength);
1324                                                         for(l=0;l<templength;l++)
1325                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1326                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1327                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1328                                                 }
1329                                         }
1330                                 }
1331                         }
1332                 }
1333                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1334
1335                 numplayers-=howmanyremoved;
1336                 funpackf(tfile, "Bi", &numpathpoints);
1337                 if(numpathpoints>30||numpathpoints<0)
1338                         numpathpoints=0;
1339                 if(numpathpoints)
1340                 {
1341                         for(j=0;j<numpathpoints;j++)
1342                         {
1343                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1344                                 for(k=0;k<numpathpointconnect[j];k++){
1345                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1346                                 }
1347                         }
1348                 }
1349                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1350
1351                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1352
1353                 SetUpLighting();
1354                 if(environment!=oldenvironment)Setenvironment(environment);
1355                 oldenvironment=environment;
1356
1357                 if(!stealthloading)
1358                 {
1359                         j=objects.numobjects;
1360                         objects.numobjects=0;
1361                         for(i=0;i<j;i++)
1362                         {
1363                                 //if(objects.type[i]!=spiketype)
1364                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1365                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1366                         }
1367
1368                         //if(skyboxtexture){
1369                         terrain.DoShadows();
1370                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1371                         objects.DoShadows();
1372                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1373                         /*}
1374                         else terrain.DoLighting();
1375                         */
1376                 }
1377
1378                 fclose(tfile);
1379
1380                 oldlevel=whichlevel;
1381
1382
1383                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1384                 for(i=0;i<numplayers;i++)
1385                 {
1386                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1387                         player[i].burnt=0;
1388                         player[i].bled=0;
1389                         player[i].onfire=0;
1390                         if(i==0||player[i].scale<0)player[i].scale=.2;
1391                         player[i].skeleton.free=0;
1392                         player[i].skeleton.id=i;
1393                         //if(Random()%2==0)player[i].creature=wolftype;
1394                         //else player[i].creature=rabbittype;
1395                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1396                         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);
1397                         else
1398                         {
1399                                 if(player[i].creature!=wolftype){
1400                                         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);
1401                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1402                                 }
1403                                 if(player[i].creature==wolftype){
1404                                         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);
1405                                 }
1406                         }
1407
1408
1409                         int texsize;
1410                         texsize=512*512*3/texdetail/texdetail;
1411                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1412                         //player[i].skeleton.skinText.resize(texsize);
1413
1414                         LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1415
1416                         if(player[i].numclothes)
1417                         {
1418                                 for(j=0;j<player[i].numclothes;j++)
1419                                 {
1420                                         tintr=player[i].clothestintr[j];
1421                                         tintg=player[i].clothestintg[j];
1422                                         tintb=player[i].clothestintb[j];
1423                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1424                                 }
1425                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1426                         }
1427
1428                         player[i].currentanimation=bounceidleanim;
1429                         player[i].targetanimation=bounceidleanim;
1430                         player[i].currentframe=0;
1431                         player[i].targetframe=1;
1432                         player[i].target=0;
1433                         player[i].speed=1+(float)(Random()%100)/1000;
1434                         if(difficulty==0)player[i].speed-=.2;
1435                         if(difficulty==1)player[i].speed-=.1;
1436
1437                         player[i].velocity=0;
1438                         player[i].oldcoords=player[i].coords;
1439                         player[i].realoldcoords=player[i].coords;
1440
1441                         player[i].id=i;
1442                         player[i].skeleton.id=i;
1443                         player[i].updatedelay=0;
1444                         player[i].normalsupdatedelay=0;
1445
1446                         player[i].aitype=passivetype;
1447                         player[i].aitarget=0;
1448                         player[i].madskills=0;
1449
1450                         if(i==0)
1451                         {
1452                                 player[i].proportionhead=1.2;
1453                                 player[i].proportionbody=1.05;
1454                                 player[i].proportionarms=1.00;
1455                                 player[i].proportionlegs=1.1;
1456                                 player[i].proportionlegs.y=1.05;
1457                         }
1458                         player[i].headless=0;
1459                         player[i].currentoffset=0;
1460                         player[i].targetoffset=0;
1461                         /*player[i].armorhead=1;
1462                         player[i].armorhigh=1;
1463                         player[i].armorlow=1;
1464                         player[i].protectionhead=1;
1465                         player[i].protectionhigh=1;
1466                         player[i].protectionlow=1;
1467                         player[i].metalhead=1;
1468                         player[i].metalhigh=1;
1469                         player[i].metallow=1;
1470                         player[i].power=1;
1471                         player[i].speedmult=1;*/
1472
1473                         player[i].damagetolerance=200;
1474
1475                         if(player[i].creature==wolftype)
1476                         {
1477                                 /*player[i].proportionhead=1.1;
1478                                 player[i].proportionbody=1.1;
1479                                 player[i].proportionarms=1.1;
1480                                 player[i].proportionlegs=1.1;
1481                                 player[i].proportionlegs.y=1.1;*/
1482                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1483
1484                                 player[i].damagetolerance=300;
1485                         }
1486
1487                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1488                         if(cellophane)
1489                         {
1490                                 player[i].proportionhead.z=0;
1491                                 player[i].proportionbody.z=0;
1492                                 player[i].proportionarms.z=0;
1493                                 player[i].proportionlegs.z=0;
1494                         }
1495
1496                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1497
1498                         player[i].headmorphness=0;
1499                         player[i].targetheadmorphness=1;
1500                         player[i].headmorphstart=0;
1501                         player[i].headmorphend=0;
1502
1503                         player[i].pausetime=0;
1504
1505                         player[i].dead=0;
1506                         player[i].jumppower=5;
1507                         player[i].damage=0;
1508                         player[i].permanentdamage=0;
1509                         player[i].superpermanentdamage=0;
1510
1511                         player[i].forwardkeydown=0;
1512                         player[i].leftkeydown=0;
1513                         player[i].backkeydown=0;
1514                         player[i].rightkeydown=0;
1515                         player[i].jumpkeydown=0;
1516                         player[i].crouchkeydown=0;
1517                         player[i].throwkeydown=0;
1518
1519                         player[i].collided=-10;
1520                         player[i].loaded=1;
1521                         player[i].bloodloss=0;
1522                         player[i].weaponactive=-1;
1523                         player[i].weaponstuck=-1;
1524                         player[i].bleeding=0;
1525                         player[i].deathbleeding=0;
1526                         player[i].stunned=0;
1527                         player[i].hasvictim=0;
1528                         player[i].wentforweapon=0;
1529                 }
1530
1531                 player[0].aitype=playercontrolled;
1532                 player[0].weaponactive=-1;
1533
1534                 if(difficulty==1)
1535                 {
1536                         //player[0].speedmult=1/.9;
1537                         player[0].power=1/.9;
1538                 }
1539
1540                 if(difficulty==0)
1541                 {
1542                         //player[0].speedmult=1/.8;
1543                         player[0].power=1/.8;
1544                 }
1545
1546                 //player[0].weaponstuck=1;
1547
1548                 if(difficulty==1)player[0].damagetolerance=250;
1549                 if(difficulty==0)player[0].damagetolerance=300;
1550                 if(difficulty==0)player[0].armorhead*=1.5;
1551                 if(difficulty==0)player[0].armorhigh*=1.5;
1552                 if(difficulty==0)player[0].armorlow*=1.5;
1553                 cameraloc=player[0].coords;
1554                 cameraloc.y+=5;
1555                 rotation=player[0].rotation;
1556
1557                 hawkcoords=player[0].coords;
1558                 hawkcoords.y+=30;
1559
1560                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1561                 //weapons.numweapons=numplayers;
1562                 for(i=0;i<weapons.numweapons;i++)
1563                 {
1564                         weapons.bloody[i]=0;
1565                         weapons.blooddrip[i]=0;
1566                         weapons.blooddripdelay[i]=0;
1567                         weapons.onfire[i]=0;
1568                         weapons.flamedelay[i]=0;
1569                         weapons.damage[i]=0;
1570                         //weapons.type[i]=sword;
1571                         if(weapons.type[i]==sword){
1572                                 weapons.mass[i]=1.5;
1573                                 weapons.tipmass[i]=1;
1574                                 weapons.length[i]=.8;
1575                         }
1576                         if(weapons.type[i]==staff){
1577                                 weapons.mass[i]=2;
1578                                 weapons.tipmass[i]=1;
1579                                 weapons.length[i]=1.5;
1580                         }
1581                         if(weapons.type[i]==knife){
1582                                 weapons.mass[i]=1;
1583                                 weapons.tipmass[i]=1.2;
1584                                 weapons.length[i]=.25;
1585                         }
1586                         weapons.position[i]=-1000;
1587                         weapons.tippoint[i]=-1000;
1588                 }
1589
1590 /*              for(i=0;i<32;i++){
1591                         //if(i<16||i>20)
1592                         OPENAL_StopSound(i);
1593                 }
1594 */
1595                 LOG("Starting background music...");
1596
1597                 OPENAL_StopSound(OPENAL_ALL);
1598                 if(environment==snowyenvironment)
1599                 {
1600                         if(ambientsound)
1601                         {
1602                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1603                                 OPENAL_SetPaused(channels[stream_wind], false);
1604                                 OPENAL_SetVolume(channels[stream_wind], 256);
1605                         }
1606                 }
1607                 else if(environment==desertenvironment)
1608                 {
1609                         if(ambientsound)
1610                         {
1611                                 //PlaySoundEx(desertambient,
1612                                 //      samp[desertambient], NULL, true);
1613                                 PlayStreamEx(stream_desertambient,
1614                                         strm[stream_desertambient], NULL, true);
1615                                 OPENAL_SetPaused(channels[stream_desertambient], false);
1616                                 OPENAL_SetVolume(channels[stream_desertambient], 256);
1617                         }
1618                 }
1619                 else if(environment==grassyenvironment)
1620                 {
1621                         if(ambientsound)
1622                         {
1623                                 //PlaySoundEx(wind, samp[wind], NULL, true);
1624                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1625                                 OPENAL_SetPaused(channels[stream_wind], false);
1626                                 OPENAL_SetVolume(channels[stream_wind], 100);
1627                         }
1628                 }
1629                 oldmusicvolume[0]=0;
1630                 oldmusicvolume[1]=0;
1631                 oldmusicvolume[2]=0;
1632                 oldmusicvolume[3]=0;
1633
1634
1635                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1636                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1637                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1638                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1639                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1640                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1641                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1642                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1643                 */
1644
1645                 if(!firstload)
1646                 {
1647                         firstload=1;
1648                 }
1649         }
1650         leveltime=0;
1651         loadingstuff=0;
1652         visibleloading=0;
1653 }
1654
1655 void    Game::Tick()
1656 {
1657         static int i,k,j,l,m;
1658         static XYZ facing,flatfacing,absflatfacing;
1659         static XYZ rotatetarget;
1660         static bool oldkey;
1661         static float oldtargetrotation;
1662         static int target, numgood;
1663         static XYZ tempcoords1,tempcoords2;
1664         static XYZ test;
1665         static XYZ test2;
1666         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1667         static int whichhit;
1668         static bool donesomething;
1669         static bool oldjumpkeydown;
1670
1671         int templength;
1672
1673         float headprop,bodyprop,armprop,legprop;
1674
1675         for(i=0;i<15;i++){
1676                 displaytime[i]+=multiplier;
1677         }
1678
1679         static unsigned char    theKeyMap[16];
1680         GetKeys( theKeyMap );
1681
1682         keyboardfrozen=0;
1683
1684
1685         static bool mainmenutogglekeydown;
1686
1687         if (IsKeyDown(theKeyMap, MAC_F6_KEY) && !freezetogglekeydown) {
1688                 if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) {
1689                         stereoreverse=true;
1690                 } else {
1691                         stereoreverse=false;
1692                 }
1693
1694                 if (stereoreverse) {
1695                         printf("Stereo reversed\n");
1696                 } else {
1697                         printf("Stereo unreversed\n");
1698                 }
1699                 freezetogglekeydown=1;
1700         }
1701
1702         if (IsKeyDown(theKeyMap, MAC_F7_KEY)) {
1703                 if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) {
1704                         stereoseparation -= 0.001;
1705                 } else {
1706                         stereoseparation -= 0.010;
1707                 }
1708
1709                 printf("Stereo decreased increased to %f\n", stereoseparation);
1710         }
1711
1712         if (IsKeyDown(theKeyMap, MAC_F8_KEY)) {
1713                 if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) {
1714                         stereoseparation += 0.001;
1715                 } else {
1716                         stereoseparation += 0.010;
1717                 }
1718
1719                 printf("Stereo separation increased to %f\n", stereoseparation);
1720         }
1721
1722
1723         if(!console){
1724                 if(mainmenu&&endgame==1)mainmenu=10;
1725                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1726                         for(j=0;j<255;j++){
1727                                 displaytext[0][j]=' ';
1728                         }
1729                         displaychars[0]=0;
1730                         displayselected=0;
1731                         entername=0;
1732                         mainmenutogglekeydown=1;
1733                 }
1734                 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)){
1735                         selected=-1;
1736                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1737                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1738                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1739                                 else if(mainmenu==0&&winfreeze){
1740                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1741                                         stealthloading=1;
1742                                         else stealthloading=0;
1743
1744                                         if(!stealthloading){
1745                                         float gLoc[3]={0,0,0};
1746                                         float vel[3]={0,0,0};
1747                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1748                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1749                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1750                                         OPENAL_SetVolume(channels[firestartsound], 256);
1751                                         OPENAL_SetPaused(channels[firestartsound], false);
1752                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1753
1754                                         flashr=1;
1755                                         flashg=0;
1756                                         flashb=0;
1757                                         flashamount=1;
1758                                         flashdelay=1;
1759                                         }
1760
1761                                         startbonustotal=0;
1762
1763                                         for(i=0;i<campaignnumlevels;i++){
1764                                         levelvisible[i]=0;
1765                                         levelhighlight[i]=0;
1766                                         }
1767
1768                                         levelorder[0]=0;
1769                                         levelvisible[0]=1;
1770                                         if(accountcampaignchoicesmade[accountactive])
1771                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1772                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1773                                         levelvisible[levelorder[i+1]]=1;
1774                                         }
1775                                         int whichlevelstart;
1776                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1777                                         if(whichlevelstart<0){
1778                                         campaignchoicenum=1;
1779                                         campaignchoicewhich[0]=0;
1780                                         }
1781                                         else
1782                                         {
1783                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1784                                         if(campaignchoicenum)
1785                                         for(i=0;i<campaignchoicenum;i++){
1786                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1787                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1788                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1789                                         }
1790                                         }
1791
1792                                         loading=2;
1793                                         loadtime=0;
1794                                         targetlevel=7;
1795                                         if(firstload)TickOnceAfter();
1796                                         if(!firstload)LoadStuff();
1797                                         //else {
1798                                         for(i=0;i<255;i++){
1799                                         mapname[i]='\0';
1800                                         }
1801                                         mapname[0]=':';
1802                                         mapname[1]='D';
1803                                         mapname[2]='a';
1804                                         mapname[3]='t';
1805                                         mapname[4]='a';
1806                                         mapname[5]=':';
1807                                         mapname[6]='M';
1808                                         mapname[7]='a';
1809                                         mapname[8]='p';
1810                                         mapname[9]='s';
1811                                         mapname[10]=':';
1812
1813                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1814                                         //accountcampaignchoicesmade[accountactive]++;
1815
1816
1817                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1818                                         whichchoice=0;
1819                                         visibleloading=1;
1820                                         stillloading=1;
1821                                         Loadlevel(mapname);
1822                                         campaign=1;
1823                                         mainmenu=0;
1824                                         gameon=1;
1825                                         OPENAL_SetPaused(channels[music3], true);
1826
1827                                         stealthloading=0;*/
1828                                 }
1829                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1830                                 if(mainmenu&&musictoggle){
1831                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1832                                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
1833                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
1834                                                 OPENAL_SetPaused(channels[stream_music3], false);
1835                                                 OPENAL_SetVolume(channels[stream_music3], 256);
1836                                                 OPENAL_SetPaused(channels[music1], true);
1837                                         }
1838                                 }
1839                                 if(!mainmenu){
1840                                         OPENAL_SetPaused(channels[stream_music3], true);
1841                                         OPENAL_SetPaused(channels[music1], false);
1842                                 }
1843                         }
1844                         if(mainmenu==3){
1845                                 float gLoc[3]={0,0,0};
1846                                 float vel[3]={0,0,0};
1847                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1848                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1849                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1850                                 OPENAL_SetVolume(channels[fireendsound], 256);
1851                                 OPENAL_SetPaused(channels[fireendsound], false);
1852                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1853
1854                                 flashr=1;
1855                                 flashg=0;
1856                                 flashb=0;
1857                                 flashamount=1;
1858                                 flashdelay=1;
1859
1860                                 if(newdetail>2)newdetail=detail;
1861                                 if(newdetail<0)newdetail=detail;
1862                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1863                                 if(newscreenheight<0)newscreenheight=screenheight;
1864
1865                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
1866                                 opstream << "Screenwidth:\n";
1867                                 opstream << newscreenwidth;
1868                                 opstream << "\nScreenheight:\n";
1869                                 opstream << newscreenheight;
1870                                 opstream << "\nMouse sensitivity:\n";
1871                                 opstream << usermousesensitivity;
1872                                 opstream << "\nBlur(0,1):\n";
1873                                 opstream << ismotionblur;
1874                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1875                                 opstream << newdetail;
1876                                 opstream << "\nFloating jump:\n";
1877                                 opstream << floatjump;
1878                                 opstream << "\nMouse jump:\n";
1879                                 opstream << mousejump;
1880                                 opstream << "\nAmbient sound:\n";
1881                                 opstream << ambientsound;
1882                                 opstream << "\nBlood (0,1,2):\n";
1883                                 opstream << bloodtoggle;
1884                                 opstream << "\nAuto slomo:\n";
1885                                 opstream << autoslomo;
1886                                 opstream << "\nFoliage:\n";
1887                                 opstream << foliage;
1888                                 opstream << "\nMusic:\n";
1889                                 opstream << musictoggle;
1890                                 opstream << "\nTrilinear:\n";
1891                                 opstream << trilinear;
1892                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1893                                 opstream << decals;
1894                                 opstream << "\nInvert mouse:\n";
1895                                 opstream << invertmouse;
1896                                 opstream << "\nGamespeed:\n";
1897                                 if(oldgamespeed==0)oldgamespeed=1;
1898                                 opstream << oldgamespeed;
1899                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1900                                 opstream << difficulty;
1901                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1902                                 opstream << damageeffects;
1903                                 opstream << "\nText:\n";
1904                                 opstream << texttoggle;
1905                                 opstream << "\nDebug:\n";
1906                                 opstream << debugmode;
1907                                 opstream << "\nVBL Sync:\n";
1908                                 opstream << vblsync;
1909                                 opstream << "\nShow Points:\n";
1910                                 opstream << showpoints;
1911                                 opstream << "\nAlways Blur:\n";
1912                                 opstream << alwaysblur;
1913                                 opstream << "\nImmediate mode (turn on on G5):\n";
1914                                 opstream << immediate;
1915                                 opstream << "\nVelocity blur:\n";
1916                                 opstream << velocityblur;
1917                             opstream << "\nVolume:\n";
1918                         opstream << volume;
1919                                 opstream << "\nForward key:\n";
1920                                 opstream << KeyToChar(forwardkey);
1921                                 opstream << "\nBack key:\n";
1922                                 opstream << KeyToChar(backkey);
1923                                 opstream << "\nLeft key:\n";
1924                                 opstream << KeyToChar(leftkey);
1925                                 opstream << "\nRight key:\n";
1926                                 opstream << KeyToChar(rightkey);
1927                                 opstream << "\nJump key:\n";
1928                                 opstream << KeyToChar(jumpkey);
1929                                 opstream << "\nCrouch key:\n";
1930                                 opstream << KeyToChar(crouchkey);
1931                                 opstream << "\nDraw key:\n";
1932                                 opstream << KeyToChar(drawkey);
1933                                 opstream << "\nThrow key:\n";
1934                                 opstream << KeyToChar(throwkey);
1935                                 opstream << "\nAttack key:\n";
1936                                 opstream << KeyToChar(attackkey);
1937                                 opstream << "\nChat key:\n";
1938                                 opstream << KeyToChar(chatkey);
1939                                 opstream.close();
1940                         }
1941                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){
1942                                 float gLoc[3]={0,0,0};
1943                                 float vel[3]={0,0,0};
1944                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1945                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1946                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1947                                 OPENAL_SetVolume(channels[fireendsound], 256);
1948                                 OPENAL_SetPaused(channels[fireendsound], false);
1949                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1950
1951                                 flashr=1;
1952                                 flashg=0;
1953                                 flashb=0;
1954                                 flashamount=1;
1955                                 flashdelay=1;
1956                         }
1957                         if(mainmenu==3&&gameon)mainmenu=2;
1958                         if(mainmenu==3&&!gameon)mainmenu=1;
1959                         if(mainmenu==5&&gameon)mainmenu=2;
1960                         if(mainmenu==5&&!gameon)mainmenu=1;
1961                         if(mainmenu==4)mainmenu=3;
1962                         if(mainmenu==6)mainmenu=5;
1963                         if(mainmenu==7)mainmenu=1;
1964                         if(mainmenu==9)mainmenu=5;
1965                         if(mainmenu==11)mainmenu=5;
1966                         if(mainmenu==13)mainmenu=12;
1967                         if(mainmenu==10)mainmenu=5;
1968                         if(mainmenu==100){
1969                                 mainmenu=5;
1970                                 gameon=0;
1971                                 winfreeze=0;
1972                         }
1973                         mainmenutogglekeydown=1;
1974                 }
1975                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1976                         mainmenutogglekeydown=0;
1977                 }
1978         }
1979
1980         /*static bool minimaptogglekeydown;
1981         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1982         minimap=1-minimap;
1983         minimaptogglekeydown=1;
1984         }
1985         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1986         minimaptogglekeydown=0;
1987         }
1988         */
1989
1990         static bool minimaptogglekeydown;
1991         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
1992                 if(tutorialstage!=51)
1993                         tutorialstagetime=tutorialmaxtime;
1994                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
1995                 OPENAL_SetVolume(channels[consolefailsound], 128);
1996                 OPENAL_SetPaused(channels[consolefailsound], false);
1997                 minimaptogglekeydown=1;
1998         }
1999         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
2000                 minimaptogglekeydown=0;
2001         }
2002
2003         if(mainmenu){
2004                 //menu buttons
2005                 if(mainmenu==1||mainmenu==2){
2006                         if(Button()&&!oldbutton&&selected==1){
2007                                 if(!gameon){
2008                                         float gLoc[3]={0,0,0};
2009                                         float vel[3]={0,0,0};
2010                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2011                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2012                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2013                                         OPENAL_SetVolume(channels[firestartsound], 256);
2014                                         OPENAL_SetPaused(channels[firestartsound], false);
2015                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2016
2017                                         flashr=1;
2018                                         flashg=0;
2019                                         flashb=0;
2020                                         flashamount=1;
2021                                         flashdelay=1;
2022
2023                                         //new game
2024                                         if(accountactive!=-1)mainmenu=5;
2025                                         else mainmenu=7;
2026                                         /*
2027                                         startbonustotal=0;
2028
2029                                         loading=2;
2030                                         loadtime=0;
2031                                         if(firstload)TickOnceAfter();
2032                                         if(!firstload)LoadStuff();
2033                                         else {
2034                                         Loadlevel(0);
2035                                         }
2036                                         mainmenu=0;
2037                                         gameon=1;
2038                                         OPENAL_SetPaused(channels[music3], true);       */
2039                                 }
2040                                 else
2041                                 {
2042                                         //resume
2043                                         mainmenu=0;
2044                                         OPENAL_SetPaused(channels[stream_music3], true);
2045                                         OPENAL_SetPaused(channels[music1], false);
2046                                 }
2047                         }
2048
2049                         if(Button()&&!oldbutton&&selected==2){
2050                                 float gLoc[3]={0,0,0};
2051                                 float vel[3]={0,0,0};
2052                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2053                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2054                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2055                                 OPENAL_SetVolume(channels[firestartsound], 256);
2056                                 OPENAL_SetPaused(channels[firestartsound], false);
2057                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2058
2059                                 flashr=1;
2060                                 flashg=0;
2061                                 flashb=0;
2062                                 flashamount=1;
2063                                 flashdelay=1;
2064
2065                                 //options
2066
2067                                 mainmenu=3;
2068
2069                                 if(newdetail>2)newdetail=detail;
2070                                 if(newdetail<0)newdetail=detail;
2071                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2072                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2073                                 if(newscreenheight>3000)newscreenheight=screenheight;
2074                                 if(newscreenheight<0)newscreenheight=screenheight;
2075                         }
2076
2077                         if(Button()&&!oldbutton&&selected==3){
2078                                 float gLoc[3]={0,0,0};
2079                                 float vel[3]={0,0,0};
2080                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2081                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2082                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2083                                 OPENAL_SetVolume(channels[fireendsound], 256);
2084                                 OPENAL_SetPaused(channels[fireendsound], false);
2085                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2086
2087                                 flashr=1;
2088                                 flashg=0;
2089                                 flashb=0;
2090                                 flashamount=1;
2091                                 flashdelay=1;
2092
2093                                 if(!gameon){
2094                                         //quit
2095                                         tryquit=1;
2096                                         OPENAL_SetPaused(channels[stream_music3], true);
2097                                 }
2098                                 else{
2099                                         //end game
2100                                         gameon=0;
2101                                         mainmenu=1;
2102                                 }
2103                         }
2104                         if(Button())oldbutton=1;
2105                         else oldbutton=0;
2106                 }
2107
2108                 if(mainmenu==3){
2109                         if(Button()&&!oldbutton&&selected!=-1){
2110                                 float gLoc[3]={0,0,0};
2111                                 float vel[3]={0,0,0};
2112                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2113                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2114                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2115                                 OPENAL_SetVolume(channels[firestartsound], 256);
2116                                 OPENAL_SetPaused(channels[firestartsound], false);
2117                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2118                         }
2119                         if(Button()&&!oldbutton&&selected==0){
2120                         
2121                                 extern SDL_Rect **resolutions;
2122                                 bool isCustomResolution = true;
2123                                 bool found = false;
2124                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2125                                 {
2126                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2127                                                 isCustomResolution = false;
2128
2129                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2130                                         {
2131                                                 i++;
2132                                                 if (resolutions[i] != NULL)
2133                                                 {
2134                                                         newscreenwidth = (int) resolutions[i]->w;
2135                                                         newscreenheight = (int) resolutions[i]->h;
2136                                                 }
2137                                                 else if (isCustomResolution)
2138                                                 {
2139                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2140                                                         {
2141                                                                 newscreenwidth = (int) resolutions[0]->w;
2142                                                                 newscreenheight = (int) resolutions[0]->h;
2143                                                         }
2144                                                         else
2145                                                         {
2146                                                                 newscreenwidth = screenwidth;
2147                                                                 newscreenheight = screenheight;
2148                                                         }
2149                                                 }
2150                                                 else
2151                                                 {
2152                                                         newscreenwidth = (int) resolutions[0]->w;
2153                                                         newscreenheight = (int) resolutions[0]->h;
2154                                                 }
2155                                                 found = true;
2156                                         }
2157                                 }
2158
2159                                 if (!found)
2160                                 {
2161                                         newscreenwidth = (int) resolutions[0]->w;
2162                                         newscreenheight = (int) resolutions[0]->h;
2163                                 }
2164
2165                                 
2166                         }
2167                         if(Button()&&!oldbutton&&selected==1){
2168                                 newdetail++;
2169                                 if(newdetail>2)newdetail=0;
2170                         }
2171                         if(Button()&&!oldbutton&&selected==2){
2172                                 bloodtoggle++;
2173                                 if(bloodtoggle>2)bloodtoggle=0;
2174                         }
2175                         if(Button()&&!oldbutton&&selected==3){
2176                                 difficulty++;
2177                                 if(difficulty>2)difficulty=0;
2178                         }
2179                         if(Button()&&!oldbutton&&selected==4){
2180                                 ismotionblur=1-ismotionblur;
2181                         }
2182                         if(Button()&&!oldbutton&&selected==5){
2183                                 decals=1-decals;
2184                         }
2185                         if(Button()&&!oldbutton&&selected==6){
2186                                 musictoggle=1-musictoggle;
2187
2188                                 if(!musictoggle){
2189                                         OPENAL_SetPaused(channels[music1], true);
2190                                         OPENAL_SetPaused(channels[stream_music2], true);
2191                                         OPENAL_SetPaused(channels[stream_music3], true);
2192
2193                                         for(i=0;i<4;i++){
2194                                                 oldmusicvolume[i]=0;
2195                                                 musicvolume[i]=0;
2196                                         }
2197                                 }
2198
2199                                 if(musictoggle){
2200                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2201                                         OPENAL_SetPaused(channels[stream_music3], false);
2202                                         OPENAL_SetVolume(channels[stream_music3], 256);
2203                                 }
2204                         }
2205                         if(Button()&&!oldbutton&&selected==9){
2206                                 invertmouse=1-invertmouse;
2207                         }
2208                         if(Button()&&!oldbutton&&selected==10){
2209                                 usermousesensitivity+=.2;
2210                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2211                         }
2212                         if(Button()&&!oldbutton&&selected==11){
2213                                 volume+=.1f;
2214                                 if(volume>1.0001f)volume=0;
2215                                 OPENAL_SetSFXMasterVolume((int)(volume*255));
2216                         }
2217                         if(Button()&&!oldbutton&&selected==7){
2218                                 /*float gLoc[3]={0,0,0};
2219                                 float vel[3]={0,0,0};
2220                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2221                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2222                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2223                                 OPENAL_SetVolume(channels[firestartsound], 256);
2224                                 OPENAL_SetPaused(channels[firestartsound], false);
2225                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2226                                 */
2227                                 flashr=1;
2228                                 flashg=0;
2229                                 flashb=0;
2230                                 flashamount=1;
2231                                 flashdelay=1;
2232
2233                                 //options
2234
2235                                 mainmenu=4;
2236                                 keyselect=-1;
2237                         }
2238                         if(Button()&&!oldbutton&&selected==8){
2239                                 float gLoc[3]={0,0,0};
2240                                 float vel[3]={0,0,0};
2241                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2242                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2243                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2244                                 OPENAL_SetVolume(channels[fireendsound], 256);
2245                                 OPENAL_SetPaused(channels[fireendsound], false);
2246                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2247
2248                                 flashr=1;
2249                                 flashg=0;
2250                                 flashb=0;
2251                                 flashamount=1;
2252                                 flashdelay=1;
2253
2254                                 if(newdetail>2)newdetail=detail;
2255                                 if(newdetail<0)newdetail=detail;
2256                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2257                                 if(newscreenheight<0)newscreenheight=screenheight;
2258
2259
2260                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2261                                 opstream << "Screenwidth:\n";
2262                                 opstream << newscreenwidth;
2263                                 opstream << "\nScreenheight:\n";
2264                                 opstream << newscreenheight;
2265                                 opstream << "\nMouse sensitivity:\n";
2266                                 opstream << usermousesensitivity;
2267                                 opstream << "\nBlur(0,1):\n";
2268                                 opstream << ismotionblur;
2269                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2270                                 opstream << newdetail;
2271                                 opstream << "\nFloating jump:\n";
2272                                 opstream << floatjump;
2273                                 opstream << "\nMouse jump:\n";
2274                                 opstream << mousejump;
2275                                 opstream << "\nAmbient sound:\n";
2276                                 opstream << ambientsound;
2277                                 opstream << "\nBlood (0,1,2):\n";
2278                                 opstream << bloodtoggle;
2279                                 opstream << "\nAuto slomo:\n";
2280                                 opstream << autoslomo;
2281                                 opstream << "\nFoliage:\n";
2282                                 opstream << foliage;
2283                                 opstream << "\nMusic:\n";
2284                                 opstream << musictoggle;
2285                                 opstream << "\nTrilinear:\n";
2286                                 opstream << trilinear;
2287                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2288                                 opstream << decals;
2289                                 opstream << "\nInvert mouse:\n";
2290                                 opstream << invertmouse;
2291                                 opstream << "\nGamespeed:\n";
2292                                 if(oldgamespeed==0)oldgamespeed=1;
2293                                 opstream << oldgamespeed;
2294                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2295                                 opstream << difficulty;
2296                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2297                                 opstream << damageeffects;
2298                                 opstream << "\nText:\n";
2299                                 opstream << texttoggle;
2300                                 opstream << "\nDebug:\n";
2301                                 opstream << debugmode;
2302                                 opstream << "\nVBL Sync:\n";
2303                                 opstream << vblsync;
2304                                 opstream << "\nShow Points:\n";
2305                                 opstream << showpoints;
2306                                 opstream << "\nAlways Blur:\n";
2307                                 opstream << alwaysblur;
2308                                 opstream << "\nImmediate mode (turn on on G5):\n";
2309                                 opstream << immediate;
2310                                 opstream << "\nVelocity blur:\n";
2311                                 opstream << velocityblur;
2312                             opstream << "\nVolume:\n";
2313                         opstream << volume;
2314                                 opstream << "\nForward key:\n";
2315                                 opstream << KeyToChar(forwardkey);
2316                                 opstream << "\nBack key:\n";
2317                                 opstream << KeyToChar(backkey);
2318                                 opstream << "\nLeft key:\n";
2319                                 opstream << KeyToChar(leftkey);
2320                                 opstream << "\nRight key:\n";
2321                                 opstream << KeyToChar(rightkey);
2322                                 opstream << "\nJump key:\n";
2323                                 opstream << KeyToChar(jumpkey);
2324                                 opstream << "\nCrouch key:\n";
2325                                 opstream << KeyToChar(crouchkey);
2326                                 opstream << "\nDraw key:\n";
2327                                 opstream << KeyToChar(drawkey);
2328                                 opstream << "\nThrow key:\n";
2329                                 opstream << KeyToChar(throwkey);
2330                                 opstream << "\nAttack key:\n";
2331                                 opstream << KeyToChar(attackkey);
2332                                 opstream << "\nChat key:\n";
2333                                 opstream << KeyToChar(chatkey);
2334                                 opstream.close();
2335
2336                                 if(mainmenu==3&&gameon)mainmenu=2;
2337                                 if(mainmenu==3&&!gameon)mainmenu=1;
2338                         }
2339                         if(Button())oldbutton=1;
2340                         else oldbutton=0;
2341                 }
2342                 if(mainmenu==4){
2343                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2344                                 float gLoc[3]={0,0,0};
2345                                 float vel[3]={0,0,0};
2346                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2347                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2348                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2349                                 OPENAL_SetVolume(channels[firestartsound], 256);
2350                                 OPENAL_SetPaused(channels[firestartsound], false);
2351                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2352                         }
2353                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2354                                 keyselect=selected;
2355                                 oldbuttons[0]=1;
2356                                 oldbuttons[1]=1;
2357                                 oldbuttons[2]=1;
2358                         }
2359                         if(keyselect!=-1){
2360                                 for(i=0;i<3;i++)
2361                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2362                                 for(i=0;i<140;i++){
2363                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2364                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2365                                                         float gLoc[3]={0,0,0};
2366                                                         float vel[3]={0,0,0};
2367                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2368                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2369                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2370                                                         OPENAL_SetVolume(channels[fireendsound], 256);
2371                                                         OPENAL_SetPaused(channels[fireendsound], false);
2372                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2373
2374                                                         int keynum;
2375                                                         keynum=i;
2376                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2377                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2378
2379
2380
2381                                                         if(keyselect==0)forwardkey=keynum;
2382                                                         if(keyselect==1)backkey=keynum;
2383                                                         if(keyselect==2)leftkey=keynum;
2384                                                         if(keyselect==3)rightkey=keynum;
2385                                                         if(keyselect==4)crouchkey=keynum;
2386                                                         if(keyselect==5)jumpkey=keynum;
2387                                                         if(keyselect==6)drawkey=keynum;
2388                                                         if(keyselect==7)throwkey=keynum;
2389                                                         if(keyselect==8)attackkey=keynum;
2390                                                         keyselect=-1;
2391                                                 }
2392                                         }
2393                                 }}
2394                         if(Button()&&!oldbutton&&selected==9){
2395                                 float gLoc[3]={0,0,0};
2396                                 float vel[3]={0,0,0};
2397                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2398                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2399                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2400                                 OPENAL_SetVolume(channels[fireendsound], 256);
2401                                 OPENAL_SetPaused(channels[fireendsound], false);
2402                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2403
2404                                 flashr=1;
2405                                 flashg=0;
2406                                 flashb=0;
2407                                 flashamount=1;
2408                                 flashdelay=1;
2409
2410                                 mainmenu=3;
2411
2412                                 if(newdetail>2)newdetail=detail;
2413                                 if(newdetail<0)newdetail=detail;
2414                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2415                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2416                                 if(newscreenheight>3000)newscreenheight=screenheight;
2417                                 if(newscreenheight<0)newscreenheight=screenheight;
2418                         }
2419                 }
2420
2421                 if(mainmenu==5){
2422
2423                         if(endgame==2){
2424                                 accountcampaignchoicesmade[accountactive]=0;
2425                                 accountcampaignscore[accountactive]=0;
2426                                 accountcampaigntime[accountactive]=0;
2427                                 endgame=0;
2428                         }
2429
2430                         if(Button()&&!oldbutton&&selected==1){
2431                                 float gLoc[3]={0,0,0};
2432                                 float vel[3]={0,0,0};
2433                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2434                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2435                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2436                                 OPENAL_SetVolume(channels[firestartsound], 256);
2437                                 OPENAL_SetPaused(channels[firestartsound], false);
2438                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2439
2440                                 flashr=1;
2441                                 flashg=0;
2442                                 flashb=0;
2443                                 flashamount=1;
2444                                 flashdelay=1;
2445
2446                                 startbonustotal=0;
2447
2448                                 loading=2;
2449                                 loadtime=0;
2450                                 targetlevel=-1;
2451                                 if(firstload)TickOnceAfter();
2452                                 if(!firstload)LoadStuff();
2453                                 else {
2454                                         Loadlevel(-1);
2455                                 }
2456
2457                                 mainmenu=0;
2458                                 gameon=1;
2459                                 OPENAL_SetPaused(channels[stream_music3], true);
2460                         }
2461                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
2462                                 float gLoc[3]={0,0,0};
2463                                 float vel[3]={0,0,0};
2464                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2465                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2466                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2467                                 OPENAL_SetVolume(channels[firestartsound], 256);
2468                                 OPENAL_SetPaused(channels[firestartsound], false);
2469                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2470
2471                                 flashr=1;
2472                                 flashg=0;
2473                                 flashb=0;
2474                                 flashamount=1;
2475                                 flashdelay=1;
2476
2477                                 startbonustotal=0;
2478
2479                                 loading=2;
2480                                 loadtime=0;
2481                                 targetlevel=7;
2482                                 if(firstload)TickOnceAfter();
2483                                 if(!firstload)LoadStuff();
2484                                 //else {
2485                                 for(i=0;i<255;i++){
2486                                         mapname[i]='\0';
2487                                 }
2488                                 mapname[0]=':';
2489                                 mapname[1]='D';
2490                                 mapname[2]='a';
2491                                 mapname[3]='t';
2492                                 mapname[4]='a';
2493                                 mapname[5]=':';
2494                                 mapname[6]='M';
2495                                 mapname[7]='a';
2496                                 mapname[8]='p';
2497                                 mapname[9]='s';
2498                                 mapname[10]=':';
2499                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2500                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2501                                 visibleloading=1;
2502                                 stillloading=1;
2503                                 Loadlevel(mapname);
2504                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2505                                 //}
2506                                 campaign=1;
2507                                 mainmenu=0;
2508                                 gameon=1;
2509                                 OPENAL_SetPaused(channels[stream_music3], true);
2510                         }
2511                         if(Button()&&!oldbutton&&selected==4){
2512                                 float gLoc[3]={0,0,0};
2513                                 float vel[3]={0,0,0};
2514                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2515                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2516                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2517                                 OPENAL_SetVolume(channels[fireendsound], 256);
2518                                 OPENAL_SetPaused(channels[fireendsound], false);
2519                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2520
2521                                 flashr=1;
2522                                 flashg=0;
2523                                 flashb=0;
2524                                 flashamount=1;
2525                                 flashdelay=1;
2526
2527                                 if(mainmenu==5&&gameon)mainmenu=2;
2528                                 if(mainmenu==5&&!gameon)mainmenu=1;
2529                         }
2530                         if(Button()&&!oldbutton&&selected==5){
2531                                 float gLoc[3]={0,0,0};
2532                                 float vel[3]={0,0,0};
2533                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2534                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2535                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2536                                 OPENAL_SetVolume(channels[fireendsound], 256);
2537                                 OPENAL_SetPaused(channels[fireendsound], false);
2538                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2539
2540                                 flashr=1;
2541                                 flashg=0;
2542                                 flashb=0;
2543                                 flashamount=1;
2544                                 flashdelay=1;
2545
2546                                 mainmenu=7;
2547                         }
2548                         if(Button()&&!oldbutton&&selected==3){
2549                                 float gLoc[3]={0,0,0};
2550                                 float vel[3]={0,0,0};
2551                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2552                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2553                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2554                                 OPENAL_SetVolume(channels[firestartsound], 256);
2555                                 OPENAL_SetPaused(channels[firestartsound], false);
2556                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2557
2558                                 flashr=1;
2559                                 flashg=0;
2560                                 flashb=0;
2561                                 flashamount=1;
2562                                 flashdelay=1;
2563
2564                                 mainmenu=6;
2565                         }
2566                         if(Button()&&!oldbutton&&selected==2){
2567                                 float gLoc[3]={0,0,0};
2568                                 float vel[3]={0,0,0};
2569                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2570                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2571                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2572                                 OPENAL_SetVolume(channels[firestartsound], 256);
2573                                 OPENAL_SetPaused(channels[firestartsound], false);
2574                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2575
2576                                 flashr=1;
2577                                 flashg=0;
2578                                 flashb=0;
2579                                 flashamount=1;
2580                                 flashdelay=1;
2581
2582                                 mainmenu=9;
2583                         }
2584                         if(Button())oldbutton=1;
2585                         else oldbutton=0;
2586                 }
2587                 if(mainmenu==9){
2588                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2589                                 float gLoc[3]={0,0,0};
2590                                 float vel[3]={0,0,0};
2591                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2592                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2593                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2594                                 OPENAL_SetVolume(channels[firestartsound], 256);
2595                                 OPENAL_SetPaused(channels[firestartsound], false);
2596                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2597
2598                                 flashr=1;
2599                                 flashg=0;
2600                                 flashb=0;
2601                                 flashamount=1;
2602                                 flashdelay=1;
2603
2604                                 startbonustotal=0;
2605
2606                                 loading=2;
2607                                 loadtime=0;
2608                                 targetlevel=selected;
2609                                 if(firstload)TickOnceAfter();
2610                                 if(!firstload)LoadStuff();
2611                                 else {
2612                                         Loadlevel(selected);
2613                                 }
2614                                 campaign=0;
2615
2616                                 mainmenu=0;
2617                                 gameon=1;
2618                                 OPENAL_SetPaused(channels[stream_music3], true);
2619                         }
2620                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2621                                 float gLoc[3]={0,0,0};
2622                                 float vel[3]={0,0,0};
2623                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2624                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2625                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2626                                 OPENAL_SetVolume(channels[fireendsound], 256);
2627                                 OPENAL_SetPaused(channels[fireendsound], false);
2628                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2629
2630                                 flashr=1;
2631                                 flashg=0;
2632                                 flashb=0;
2633                                 flashamount=1;
2634                                 flashdelay=1;
2635
2636                                 mainmenu=5;
2637                         }
2638                         if(Button())oldbutton=1;
2639                         else oldbutton=0;
2640                 }
2641                 if(mainmenu==11){
2642                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2643                                 float gLoc[3]={0,0,0};
2644                                 float vel[3]={0,0,0};
2645                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2646                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2647                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2648                                 OPENAL_SetVolume(channels[firestartsound], 256);
2649                                 OPENAL_SetPaused(channels[firestartsound], false);
2650                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2651
2652                                 flashr=1;
2653                                 flashg=0;
2654                                 flashb=0;
2655                                 flashamount=1;
2656                                 flashdelay=1;
2657
2658                                 startbonustotal=0;
2659
2660                                 loading=2;
2661                                 loadtime=0;
2662                                 targetlevel=selected;
2663                                 if(firstload)TickOnceAfter();
2664                                 if(!firstload)LoadStuff();
2665                                 else {
2666                                         Loadlevel(selected);
2667                                 }
2668                                 campaign=0;
2669
2670                                 mainmenu=0;
2671                                 gameon=1;
2672                                 OPENAL_SetPaused(channels[stream_music3], true);
2673                         }
2674                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2675                                 float gLoc[3]={0,0,0};
2676                                 float vel[3]={0,0,0};
2677                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2678                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2679                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2680                                 OPENAL_SetVolume(channels[fireendsound], 256);
2681                                 OPENAL_SetPaused(channels[fireendsound], false);
2682                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2683
2684                                 flashr=1;
2685                                 flashg=0;
2686                                 flashb=0;
2687                                 flashamount=1;
2688                                 flashdelay=1;
2689
2690                                 mainmenu=5;
2691                         }
2692                         if(Button())oldbutton=1;
2693                         else oldbutton=0;
2694                 }
2695                 if(mainmenu==10){
2696                         endgame=2;
2697                         if(Button()&&!oldbutton&&selected==3){
2698                                 float gLoc[3]={0,0,0};
2699                                 float vel[3]={0,0,0};
2700                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2701                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2702                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2703                                 OPENAL_SetVolume(channels[fireendsound], 256);
2704                                 OPENAL_SetPaused(channels[fireendsound], false);
2705                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2706
2707                                 flashr=1;
2708                                 flashg=0;
2709                                 flashb=0;
2710                                 flashamount=1;
2711                                 flashdelay=1;
2712
2713                                 mainmenu=5;
2714                         }
2715                         if(Button())oldbutton=1;
2716                         else oldbutton=0;
2717                 }
2718
2719                 if(mainmenu==6){
2720                         if(Button()&&!oldbutton&&selected!=-1){
2721                                 float gLoc[3]={0,0,0};
2722                                 float vel[3]={0,0,0};
2723                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2724                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2725                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2726                                 OPENAL_SetVolume(channels[firestartsound], 256);
2727                                 OPENAL_SetPaused(channels[firestartsound], false);
2728                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2729                         }
2730                         if(Button()&&!oldbutton&&selected==1){
2731                                 float gLoc[3]={0,0,0};
2732                                 float vel[3]={0,0,0};
2733                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2734                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2735                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2736                                 OPENAL_SetVolume(channels[fireendsound], 256);
2737                                 OPENAL_SetPaused(channels[fireendsound], false);
2738                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2739
2740                                 flashr=1;
2741                                 flashg=0;
2742                                 flashb=0;
2743                                 flashamount=1;
2744                                 flashdelay=1;
2745
2746                                 for(i=accountactive;i<numaccounts-1;i++){
2747                                         accountdifficulty[i]=accountdifficulty[i+1];
2748                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2749                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2750                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2751                                         }
2752                                         accountpoints[i]=accountpoints[i+1];
2753                                         for(j=0;j<50;j++){
2754                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2755                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2756                                         }
2757                                         for(j=0;j<60;j++){
2758                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2759                                         }
2760                                         for(j=0;j<256;j++){
2761                                                 accountname[i][j]=accountname[i+1][j];
2762                                         }
2763                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2764                                         accountprogress[i]=accountprogress[i+1];
2765                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2766                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2767                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2768                                 }
2769
2770                                 numaccounts--;
2771                                 accountactive=-1;
2772
2773
2774                                 mainmenu=7;
2775                         }
2776                         if(Button()&&!oldbutton&&selected==2){
2777                                 float gLoc[3]={0,0,0};
2778                                 float vel[3]={0,0,0};
2779                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2780                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2781                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2782                                 OPENAL_SetVolume(channels[fireendsound], 256);
2783                                 OPENAL_SetPaused(channels[fireendsound], false);
2784                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2785
2786                                 flashr=1;
2787                                 flashg=0;
2788                                 flashb=0;
2789                                 flashamount=1;
2790                                 flashdelay=1;
2791
2792                                 mainmenu=5;
2793                         }
2794                         if(Button())oldbutton=1;
2795                         else oldbutton=0;
2796                 }
2797                 if(mainmenu==7){
2798                         if(Button()&&!oldbutton&&selected!=-1){
2799                                 float gLoc[3]={0,0,0};
2800                                 float vel[3]={0,0,0};
2801                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2802                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2803                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2804                                 OPENAL_SetVolume(channels[firestartsound], 256);
2805                                 OPENAL_SetPaused(channels[firestartsound], false);
2806                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2807                         }
2808                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2809                                 entername=1;
2810                         }
2811                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2812                                 accountactive=selected-1;
2813                                 mainmenu=5;
2814                                 flashr=1;
2815                                 flashg=0;
2816                                 flashb=0;
2817                                 flashamount=1;
2818                                 flashdelay=1;
2819                         }
2820                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2821                                 float gLoc[3]={0,0,0};
2822                                 float vel[3]={0,0,0};
2823                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2824                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2825                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2826                                 OPENAL_SetVolume(channels[fireendsound], 256);
2827                                 OPENAL_SetPaused(channels[fireendsound], false);
2828                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2829
2830                                 flashr=1;
2831                                 flashg=0;
2832                                 flashb=0;
2833                                 flashamount=1;
2834                                 flashdelay=1;
2835
2836                                 mainmenu=1;
2837
2838                                 for(j=0;j<255;j++){
2839                                         displaytext[0][j]=' ';
2840                                 }
2841                                 displaychars[0]=0;
2842                                 displayselected=0;
2843                                 entername=0;
2844                         }
2845                         if(Button())oldbutton=1;
2846                         else oldbutton=0;
2847                 }
2848                 if(mainmenu==8){
2849                         if(Button()&&!oldbutton&&selected!=-1){
2850                                 float gLoc[3]={0,0,0};
2851                                 float vel[3]={0,0,0};
2852                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2853                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2854                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2855                                 OPENAL_SetVolume(channels[firestartsound], 256);
2856                                 OPENAL_SetPaused(channels[firestartsound], false);
2857                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2858
2859                                 if(selected==0)accountdifficulty[accountactive]=0;
2860                                 if(selected==1)accountdifficulty[accountactive]=1;
2861                                 if(selected==2)accountdifficulty[accountactive]=2;
2862
2863                                 mainmenu=5;
2864
2865                                 flashr=1;
2866                                 flashg=0;
2867                                 flashb=0;
2868                                 flashamount=1;
2869                                 flashdelay=1;
2870
2871                         }
2872                         if(Button())oldbutton=1;
2873                         else oldbutton=0;
2874                 }
2875
2876
2877                 if(Button())oldbutton=1;
2878                 else oldbutton=0;
2879
2880                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
2881                         tryquit=1;
2882                         if(mainmenu==3){
2883                                 if(newdetail>2)newdetail=detail;
2884                                 if(newdetail<0)newdetail=detail;
2885                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2886                                 if(newscreenheight<0)newscreenheight=screenheight;
2887
2888                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2889                                 opstream << "Screenwidth:\n";
2890                                 opstream << newscreenwidth;
2891                                 opstream << "\nScreenheight:\n";
2892                                 opstream << newscreenheight;
2893                                 opstream << "\nMouse sensitivity:\n";
2894                                 opstream << usermousesensitivity;
2895                                 opstream << "\nBlur(0,1):\n";
2896                                 opstream << ismotionblur;
2897                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2898                                 opstream << newdetail;
2899                                 opstream << "\nFloating jump:\n";
2900                                 opstream << floatjump;
2901                                 opstream << "\nMouse jump:\n";
2902                                 opstream << mousejump;
2903                                 opstream << "\nAmbient sound:\n";
2904                                 opstream << ambientsound;
2905                                 opstream << "\nBlood (0,1,2):\n";
2906                                 opstream << bloodtoggle;
2907                                 opstream << "\nAuto slomo:\n";
2908                                 opstream << autoslomo;
2909                                 opstream << "\nFoliage:\n";
2910                                 opstream << foliage;
2911                                 opstream << "\nMusic:\n";
2912                                 opstream << musictoggle;
2913                                 opstream << "\nTrilinear:\n";
2914                                 opstream << trilinear;
2915                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2916                                 opstream << decals;
2917                                 opstream << "\nInvert mouse:\n";
2918                                 opstream << invertmouse;
2919                                 opstream << "\nGamespeed:\n";
2920                                 if(oldgamespeed==0)oldgamespeed=1;
2921                                 opstream << oldgamespeed;
2922                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2923                                 opstream << difficulty;
2924                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2925                                 opstream << damageeffects;
2926                                 opstream << "\nText:\n";
2927                                 opstream << texttoggle;
2928                                 opstream << "\nDebug:\n";
2929                                 opstream << debugmode;
2930                                 opstream << "\nVBL Sync:\n";
2931                                 opstream << vblsync;
2932                                 opstream << "\nShow Points:\n";
2933                                 opstream << showpoints;
2934                                 opstream << "\nAlways Blur:\n";
2935                                 opstream << alwaysblur;
2936                                 opstream << "\nImmediate mode (turn on on G5):\n";
2937                                 opstream << immediate;
2938                                 opstream << "\nVelocity blur:\n";
2939                                 opstream << velocityblur;
2940                             opstream << "\nVolume:\n";
2941                         opstream << volume;
2942                                 opstream << "\nForward key:\n";
2943                                 opstream << KeyToChar(forwardkey);
2944                                 opstream << "\nBack key:\n";
2945                                 opstream << KeyToChar(backkey);
2946                                 opstream << "\nLeft key:\n";
2947                                 opstream << KeyToChar(leftkey);
2948                                 opstream << "\nRight key:\n";
2949                                 opstream << KeyToChar(rightkey);
2950                                 opstream << "\nJump key:\n";
2951                                 opstream << KeyToChar(jumpkey);
2952                                 opstream << "\nCrouch key:\n";
2953                                 opstream << KeyToChar(crouchkey);
2954                                 opstream << "\nDraw key:\n";
2955                                 opstream << KeyToChar(drawkey);
2956                                 opstream << "\nThrow key:\n";
2957                                 opstream << KeyToChar(throwkey);
2958                                 opstream << "\nAttack key:\n";
2959                                 opstream << KeyToChar(attackkey);
2960                                 opstream << "\nChat key:\n";
2961                                 opstream << KeyToChar(chatkey);
2962                                 opstream.close();
2963                         }
2964                 }
2965
2966                 if(mainmenu==1||mainmenu==2){
2967                         if(loaddistrib>4)transition+=multiplier/8;
2968                         if(transition>1){
2969                                 transition=0;
2970                                 anim++;
2971                                 if(anim>4)anim=0;
2972                                 loaddistrib=0;
2973                         }
2974                 }
2975                 OPENAL_SetFrequency(channels[stream_music3], 22050);
2976
2977                 if(entername){
2978                         for(i=0;i<140;i++){
2979                                 if(IsKeyDown(theKeyMap, i)){
2980                                         togglekeydelay[i]+=multiplier;
2981                                         if(togglekeydelay[i]>.4){
2982                                                 togglekey[i]=0;
2983                                                 togglekeydelay[i]=.36;
2984                                         }
2985                                         if(!togglekey[i]){
2986                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
2987                                                         for(j=255;j>=displayselected+1;j--){
2988                                                                 displaytext[0][j]=displaytext[0][j-1];
2989                                                         }
2990                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
2991                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
2992                                                         displayselected++;
2993                                                         displaychars[0]++;
2994                                                 }
2995                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
2996                                                         for(j=displayselected-1;j<255;j++){
2997                                                                 displaytext[0][j]=displaytext[0][j+1];
2998                                                         }
2999                                                         displaytext[0][255]=' ';
3000                                                         displayselected--;
3001                                                         displaychars[0]--;
3002                                                 }
3003                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3004                                                         displayselected--;
3005                                                 }
3006                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3007                                                         displayselected++;
3008                                                 }
3009                                                 if(i==MAC_RETURN_KEY&&entername){
3010                                                         if(displaychars[0]){
3011                                                                 numaccounts++;
3012                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
3013                                                                 accountactive=numaccounts-1;
3014                                                                 accountdifficulty[accountactive]=1;
3015                                                                 accountprogress[accountactive]=0;
3016                                                                 accountpoints[accountactive]=0;
3017                                                                 accountcampaigntime[accountactive]=0;
3018                                                                 accountcampaignscore[accountactive]=0;
3019                                                                 accountcampaignfasttime[accountactive]=0;
3020                                                                 accountcampaignhighscore[accountactive]=0;
3021                                                                 for(j=0;j<50;j++){
3022                                                                         accounthighscore[accountactive][j]=0;
3023                                                                         accountfasttime[accountactive][j]=0;
3024                                                                 }
3025                                                                 for(j=0;j<60;j++){
3026                                                                         accountunlocked[accountactive][j]=0;
3027                                                                 }
3028                                                                 accountcampaignchoicesmade[accountactive]=0;
3029
3030                                                                 for(j=0;j<255;j++){
3031                                                                         displaytext[0][j]=' ';
3032                                                                 }
3033                                                                 displaychars[0]=0;
3034                                                                 displayselected=0;
3035                                                                 entername=0;
3036
3037                                                                 mainmenu=8;
3038
3039                                                                 flashr=1;
3040                                                                 flashg=0;
3041                                                                 flashb=0;
3042                                                                 flashamount=1;
3043                                                                 flashdelay=1;
3044
3045                                                                 float gLoc[3]={0,0,0};
3046                                                                 float vel[3]={0,0,0};
3047                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3048                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3049                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3050                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3051                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3052                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3053
3054                                                                 for(j=0;j<255;j++){
3055                                                                         displaytext[0][j]=' ';
3056                                                                 }
3057                                                                 displaychars[0]=0;
3058
3059
3060                                                                 displayselected=0;
3061                                                         }}
3062
3063                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3064                                                         if(displaychars[0]){
3065                                                                 sprintf (registrationname, "%s", displaytext[0]);
3066                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3067
3068                                                                 mainmenu=5;
3069                         
3070                                                                 flashr=1;
3071                                                                 flashg=0;
3072                                                                 flashb=0;
3073                                                                 flashamount=1;
3074                                                                 flashdelay=1;
3075
3076                                                                 float gLoc[3]={0,0,0};
3077                                                                 float vel[3]={0,0,0};
3078                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3079                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3080                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3081                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3082                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3083                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3084
3085                                                                 for(j=0;j<255;j++){
3086                                                                         displaytext[0][j]=' ';
3087                                                                 }
3088                                                                 displaychars[0]=0;
3089                         
3090                                                                 displayselected=0;
3091                                                         }}
3092                                         }
3093                                         togglekey[i]=1;
3094                                 }
3095                                 else {
3096                                         togglekey[i]=0;
3097                                         togglekeydelay[i]=0;
3098                                 }
3099                         }
3100
3101                         displayblinkdelay-=multiplier;
3102                         if(displayblinkdelay<=0){
3103                                 displayblinkdelay=.3;
3104                                 displayblink=1-displayblink;
3105                         }
3106                 }
3107         }
3108
3109         if(!mainmenu){
3110                 if(hostile==1)hostiletime+=multiplier;
3111                 else hostiletime=0;
3112                 if(!winfreeze)leveltime+=multiplier;
3113                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3114                         chatting=0;
3115                         console=0;
3116                         freeze=0;
3117                         displaychars[0]=0;
3118                 }
3119
3120                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3121                         chatting=1;
3122                         chattogglekeydown=1;
3123                         togglekey[chatkey]=1;
3124                         togglekeydelay[chatkey]=-20;
3125                 }
3126
3127                 if(!IsKeyDown(theKeyMap, chatkey)){
3128                         chattogglekeydown=0;
3129                 }
3130
3131                 if(chatting){
3132                         for(i=0;i<140;i++){
3133                                 if(IsKeyDown(theKeyMap, i)){
3134                                         togglekeydelay[i]+=multiplier;
3135                                         if(togglekeydelay[i]>.4){
3136                                                 togglekey[i]=0;
3137                                                 togglekeydelay[i]=.36;
3138                                         }
3139                                         if(!togglekey[i]){
3140                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3141                                                         for(j=255;j>=displayselected+1;j--){
3142                                                                 displaytext[0][j]=displaytext[0][j-1];
3143                                                         }
3144                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3145                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3146                                                         displayselected++;
3147                                                         displaychars[0]++;
3148                                                 }
3149                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3150                                                         for(j=displayselected-1;j<255;j++){
3151                                                                 displaytext[0][j]=displaytext[0][j+1];
3152                                                         }
3153                                                         displaytext[0][255]=' ';
3154                                                         displayselected--;
3155                                                         displaychars[0]--;
3156                                                 }
3157                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3158                                                         displayselected--;
3159                                                 }
3160                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3161                                                         displayselected++;
3162                                                 }
3163                                                 if(i==MAC_RETURN_KEY){
3164                                                         if(displaychars[0]){
3165                                                                 /*for(j=0;j<displaychars[0];j++){
3166                                                                 talkname[j]=displaytext[0][j];
3167                                                                 }
3168                                                                 talkname[displaychars[0]]='\0';
3169                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3170                                                                 //NetworkSendInformation(chatname);
3171                                                                 */
3172                                                                 for(j=0;j<255;j++){
3173                                                                         displaytext[0][j]=' ';
3174                                                                 }
3175                                                                 displaychars[0]=0;
3176                                                                 displayselected=0;
3177                                                                 chatting=0;
3178                                                         }
3179                                                 }
3180                                         }
3181                                         togglekey[i]=1;
3182                                 }
3183                                 else {
3184                                         togglekey[i]=0;
3185                                         togglekeydelay[i]=0;
3186                                 }
3187                         }
3188
3189                         displayblinkdelay-=multiplier;
3190                         if(displayblinkdelay<=0){
3191                                 displayblinkdelay=.3;
3192                                 displayblink=1-displayblink;
3193                         }
3194                 }
3195
3196                 if(chatting)keyboardfrozen=1;
3197
3198                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3199                         freeze=1-freeze;
3200                         if(freeze){
3201                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3202                         }
3203                         freezetogglekeydown=1;
3204                 }
3205
3206                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3207                         freezetogglekeydown=0;
3208                 }
3209
3210                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3211                         console=1-console;
3212                         if(!console)freeze=0;
3213                         if(console){
3214                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3215                         }
3216                         consoletogglekeydown=1;
3217                 }
3218
3219                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3220                         consoletogglekeydown=0;
3221                 }
3222
3223                 if(console)freeze=1;
3224
3225                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3226                         for(i=0;i<140;i++){
3227                                 if(IsKeyDown(theKeyMap, i)){
3228                                         togglekeydelay[i]+=multiplier;
3229                                         if(togglekeydelay[i]>.4){
3230                                                 togglekey[i]=0;
3231                                                 togglekeydelay[i]=.36;
3232                                         }
3233                                         if(!togglekey[i]){
3234                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3235                                                         for(j=255;j>=consoleselected+1;j--){
3236                                                                 consoletext[0][j]=consoletext[0][j-1];
3237                                                         }
3238                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3239                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3240                                                         consoleselected++;
3241                                                         consolechars[0]++;
3242                                                 }
3243                                                 else if(i==MAC_ENTER_KEY){
3244                                                         for(j=255;j>=consoleselected+1;j--){
3245                                                                 consoletext[0][j]=consoletext[0][j-1];
3246                                                         }
3247                                                         consoletext[0][consoleselected]='\n';
3248                                                         consoleselected++;
3249                                                         consolechars[0]++;
3250                                                 }
3251                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3252                                                         for(j=consoleselected-1;j<255;j++){
3253                                                                 consoletext[0][j]=consoletext[0][j+1];
3254                                                         }
3255                                                         consoletext[0][255]=' ';
3256                                                         consoleselected--;
3257                                                         consolechars[0]--;
3258                                                 }
3259                                                 if(i==MAC_ARROW_UP_KEY){
3260                                                         if(archiveselected<14)archiveselected++;
3261                                                         for(j=0;j<255;j++){
3262                                                                 consolechars[0]=consolechars[archiveselected];
3263                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3264                                                                 consoleselected=consolechars[0];
3265                                                         }
3266                                                 }
3267                                                 if(i==MAC_ARROW_DOWN_KEY){
3268                                                         if(archiveselected>0)archiveselected--;
3269                                                         for(j=0;j<255;j++){
3270                                                                 consolechars[0]=consolechars[archiveselected];
3271                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3272                                                                 consoleselected=consolechars[0];
3273                                                         }
3274                                                 }
3275                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3276                                                         consoleselected--;
3277                                                 }
3278                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3279                                                         consoleselected++;
3280                                                 }
3281                                                 if(i==MAC_RETURN_KEY){
3282                                                         archiveselected=0;
3283                                                         donesomething=0;
3284                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3285                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3286                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3287                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3288                                                                 donesomething=1;
3289                                                                 tryquit=1;
3290                                                         }
3291                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3292                                                         for(j=5;j<consolechars[0];j++){
3293                                                         talkname[j-5]=consoletext[0][j];
3294                                                         }
3295                                                         talkname[consolechars[0]-5]='\0';
3296                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3297                                                         //NetworkSendInformation(chatname);
3298                                                         donesomething=1;
3299                                                         }
3300                                                         if(Compare(consoletext[0],"name ",0,4)){
3301                                                         int numchars;
3302                                                         numchars=consolechars[0]-5;
3303                                                         if(numchars>32)numchars=32;
3304                                                         for(j=5;j<numchars+5;j++){
3305                                                         talkname[j-5]=consoletext[0][j];
3306                                                         }
3307                                                         talkname[numchars]='\0';
3308                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3309                                                         //NetworkSendInformation(chatname);
3310                                                         sprintf (playerName, "%s",talkname);
3311                                                         //NetworkSendName(playerName);
3312                                                         donesomething=1;
3313                                                         }*/
3314                                                         if(Compare(consoletext[0],"map ",0,3)){
3315                                                                 mapname[0]=':';
3316                                                                 mapname[1]='D';
3317                                                                 mapname[2]='a';
3318                                                                 mapname[3]='t';
3319                                                                 mapname[4]='a';
3320                                                                 mapname[5]=':';
3321                                                                 mapname[6]='M';
3322                                                                 mapname[7]='a';
3323                                                                 mapname[8]='p';
3324                                                                 mapname[9]='s';
3325                                                                 mapname[10]=':';
3326                                                                 for(j=4;j<consolechars[0];j++){
3327                                                                         mapname[j-4+11]=consoletext[0][j];
3328                                                                 }
3329                                                                 mapname[consolechars[0]-4+11]='\0';
3330                                                                 Loadlevel(mapname);
3331                                                                 whichlevel=-2;
3332                                                                 campaign=0;
3333                                                                 donesomething=1;
3334                                                         }
3335                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3336                                                         int v;
3337                                                         unsigned char playerNameStr[32];
3338                                                         char theIPAddress[256];
3339                                                         char thePort[32];
3340                                                         NMUInt32 port = 25710;
3341
3342                                                         strcpy(playerName, "Client");
3343                                                         GameC2PStr( playerName, playerNameStr );
3344
3345                                                         for(j=0;j<consolechars[0]-8;j++){
3346                                                         theIPAddress[j]=consoletext[0][j+8];
3347                                                         }
3348                                                         theIPAddress[consolechars[0]-8]='\0';
3349
3350                                                         sprintf( thePort, "%li", port );
3351                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3352                                                         if(v)
3353                                                         {
3354                                                         if(consolechars[0]>0){
3355                                                         for(k=14;k>=1;k--){
3356                                                         for(j=0;j<255;j++){
3357                                                         consoletext[k][j]=consoletext[k-1][j];
3358                                                         }
3359                                                         consolechars[k]=consolechars[k-1];
3360                                                         }
3361                                                         for(j=0;j<255;j++){
3362                                                         consoletext[0][j]=' ';
3363                                                         }
3364                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3365                                                         else sprintf (consoletext[0], "Could not open connection");
3366
3367                                                         consolechars[0]=255;
3368                                                         consoleselected=0;
3369                                                         }
3370                                                         }
3371                                                         else
3372                                                         {
3373                                                         donesomething=1;
3374                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3375                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3376                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3377
3378                                                         if(consolechars[0]>0){
3379                                                         for(k=14;k>=1;k--){
3380                                                         for(j=0;j<255;j++){
3381                                                         consoletext[k][j]=consoletext[k-1][j];
3382                                                         }
3383                                                         consolechars[k]=consolechars[k-1];
3384                                                         }
3385                                                         for(j=0;j<255;j++){
3386                                                         consoletext[0][j]=' ';
3387                                                         }
3388                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3389
3390                                                         consolechars[0]=255;
3391                                                         consoleselected=0;
3392                                                         }
3393                                                         }
3394                                                         }
3395
3396                                                         if(Compare(consoletext[0],"host ",0,4)){
3397                                                         unsigned char gameNameStr[32], playerNameStr[32];
3398                                                         char gameName[32];//, playerName[32];
3399                                                         NMUInt32 port;
3400                                                         int players;
3401                                                         int v;
3402
3403                                                         port = 25710;
3404                                                         players =4;
3405
3406                                                         strcpy(gameName, "Host's game");
3407                                                         strcpy(playerName, "Host");
3408                                                         GameC2PStr( gameName, gameNameStr );
3409                                                         GameC2PStr( playerName, playerNameStr );
3410
3411                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3412                                                         if(v)
3413                                                         {
3414                                                         if(consolechars[0]>0){
3415                                                         for(k=14;k>=1;k--){
3416                                                         for(j=0;j<255;j++){
3417                                                         consoletext[k][j]=consoletext[k-1][j];
3418                                                         }
3419                                                         consolechars[k]=consolechars[k-1];
3420                                                         }
3421                                                         for(j=0;j<255;j++){
3422                                                         consoletext[0][j]=' ';
3423                                                         }
3424                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3425
3426                                                         consolechars[0]=255;
3427                                                         consoleselected=0;
3428                                                         }
3429                                                         }
3430                                                         else
3431                                                         {
3432                                                         donesomething=1;
3433                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3434                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3435                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3436
3437                                                         if(consolechars[0]>0){
3438                                                         for(k=14;k>=1;k--){
3439                                                         for(j=0;j<255;j++){
3440                                                         consoletext[k][j]=consoletext[k-1][j];
3441                                                         }
3442                                                         consolechars[k]=consolechars[k-1];
3443                                                         }
3444                                                         for(j=0;j<255;j++){
3445                                                         consoletext[0][j]=' ';
3446                                                         }
3447                                                         sprintf (consoletext[0], "Game hosted");
3448
3449                                                         consolechars[0]=255;
3450                                                         consoleselected=0;
3451                                                         }
3452                                                         }
3453                                                         }
3454                                                         */
3455                                                         if(Compare(consoletext[0],"save ",0,4)){
3456                                                                 mapname[0]=':';
3457                                                                 mapname[1]='D';
3458                                                                 mapname[2]='a';
3459                                                                 mapname[3]='t';
3460                                                                 mapname[4]='a';
3461                                                                 mapname[5]=':';
3462                                                                 mapname[6]='M';
3463                                                                 mapname[7]='a';
3464                                                                 mapname[8]='p';
3465                                                                 mapname[9]='s';
3466                                                                 mapname[10]=':';
3467                                                                 for(j=5;j<consolechars[0];j++){
3468                                                                         mapname[j-5+11]=consoletext[0][j];
3469                                                                 }
3470                                                                 mapname[consolechars[0]-5+11]='\0';
3471
3472                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3473                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3474                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3475
3476                                                                 int mapvers;
3477                                                                 mapvers=12;
3478
3479
3480                                                                 FILE                    *tfile;
3481                                                                 tfile=fopen( ConvertFileName(mapname), "wb" );
3482                                                                 fpackf(tfile, "Bi", mapvers);
3483                                                                 //fpackf(tfile, "Bi", indemo);
3484                                                                 fpackf(tfile, "Bi", maptype);
3485                                                                 fpackf(tfile, "Bi", hostile);
3486                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3487                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3488                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3489                                                                 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);
3490                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3491                                                                         for(j=0;j<player[0].num_weapons;j++){
3492                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3493                                                                         }
3494
3495                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3496                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3497                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3498                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3499
3500                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3501
3502                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3503
3504                                                                         fpackf(tfile, "Bi", numdialogues);
3505                                                                         if(numdialogues)
3506                                                                                 for(k=0;k<numdialogues;k++){
3507                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3508                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3509                                                                                         for(l=0;l<10;l++){
3510                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3511                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3512                                                                                         }
3513                                                                                         if(numdialogueboxes)
3514                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3515                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3516                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3517                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3518                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3519                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3520
3521                                                                                                         templength=strlen(dialoguetext[k][l]);
3522                                                                                                         fpackf(tfile, "Bi",(templength));
3523                                                                                                         for(m=0;m<templength;m++){
3524                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3525                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3526                                                                                                         }
3527
3528                                                                                                         templength=strlen(dialoguename[k][l]);
3529                                                                                                         fpackf(tfile, "Bi",templength);
3530                                                                                                         for(m=0;m<templength;m++){
3531                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3532                                                                                                                 if(dialoguename[k][l][m]=='\0')break;
3533                                                                                                         }
3534
3535                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3536                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3537                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3538
3539                                                                                                         for(m=0;m<10;m++)
3540                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3541
3542                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3543                                                                                                 }
3544                                                                                 }
3545
3546                                                                                 if(player[0].numclothes)
3547                                                                                         for(k=0;k<player[0].numclothes;k++){
3548                                                                                                 templength=strlen(player[0].clothes[k]);
3549                                                                                                 fpackf(tfile, "Bi", templength);
3550                                                                                                 for(l=0;l<templength;l++)
3551                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3552                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
3553                                                                                         }
3554
3555                                                                                         fpackf(tfile, "Bi", environment);
3556
3557                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3558
3559                                                                                         if(objects.numobjects)
3560                                                                                                 for(k=0;k<objects.numobjects;k++){
3561                                                                                                         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]);
3562                                                                                                 }
3563
3564                                                                                                 fpackf(tfile, "Bi", numhotspots);
3565                                                                                                 if(numhotspots)
3566                                                                                                         for(i=0;i<numhotspots;i++){
3567                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3568                                                                                                                 templength=strlen(hotspottext[i]);
3569                                                                                                                 fpackf(tfile, "Bi",templength);
3570                                                                                                                 for(l=0;l<templength;l++)
3571                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3572                                                                                                         }
3573
3574                                                                                                         fpackf(tfile, "Bi", numplayers);
3575                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3576                                                                                                                 for(j=1;j<numplayers;j++){
3577                                                                                                                         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);
3578                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3579                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3580                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3581                                                                                                                                 }
3582                                                                                                                                 if(player[j].numwaypoints<30){
3583                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3584                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3585                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3586                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3587                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3588                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3589                                                                                                                                         }
3590                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3591                                                                                                                                 }
3592                                                                                                                                 else{
3593                                                                                                                                         player[j].numwaypoints=0;
3594                                                                                                                                         player[j].waypoint=0;
3595                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3596                                                                                                                                 }
3597
3598                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3599                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3600                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3601                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3602
3603                                                                                                                                 if(player[j].creature==wolftype){
3604                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3605                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3606                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3607                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3608                                                                                                                                 }
3609
3610                                                                                                                                 if(player[j].creature==rabbittype){
3611                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3612                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3613                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3614                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3615                                                                                                                                 }
3616
3617                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3618
3619
3620
3621                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3622                                                                                                                                 if(player[j].numclothes)
3623                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3624                                                                                                                                                 int templength;
3625                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3626                                                                                                                                                 fpackf(tfile, "Bi", templength);
3627                                                                                                                                                 for(l=0;l<templength;l++)
3628                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3629                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
3630                                                                                                                                         }
3631                                                                                                                 }
3632
3633                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3634                                                                                                                 if(numpathpoints)
3635                                                                                                                         for(j=0;j<numpathpoints;j++){
3636                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3637                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3638                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3639                                                                                                                                 }
3640                                                                                                                         }
3641
3642                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3643
3644
3645                                                                                                                         fclose(tfile);
3646                                                                                                                         donesomething=1;
3647
3648                                                                                                                         /*
3649                                                                                                                         FILE                    *tfile;
3650                                                                                                                         tfile=fopen( mapname, "wb" );
3651                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3652                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3653                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3654                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3655                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3656                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3657                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3658                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3659                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3660                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3661                                                                                                                         }
3662
3663                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3664                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3665                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3666                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3667                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3668                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3669                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3670                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3671                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3672                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3673                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3674
3675                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3676                                                                                                                         if(player[0].numclothes)
3677                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3678                                                                                                                         int templength;
3679                                                                                                                         templength=strlen(player[0].clothes[k]);
3680                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3681                                                                                                                         for(l=0;l<templength;l++)
3682                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3683                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);
3684                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);
3685                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);
3686                                                                                                                         }
3687
3688                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3689
3690                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3691
3692                                                                                                                         for(k=0;k<objects.numobjects;k++){
3693                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3694                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3695                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3696                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3697                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3698                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3699                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3700                                                                                                                         }
3701
3702                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3703                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3704                                                                                                                         for(j=1;j<numplayers;j++){
3705                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3706                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3707                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3708                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3709                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3710                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3711                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3712                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3713                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3714                                                                                                                         }
3715                                                                                                                         if(player[j].numwaypoints<30){
3716                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3717                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3718                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3719                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3720                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3721                                                                                                                         }
3722                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3723                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3724                                                                                                                         }
3725                                                                                                                         else{
3726                                                                                                                         player[j].numwaypoints=0;
3727                                                                                                                         player[j].waypoint=0;
3728                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3729                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3730                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3731                                                                                                                         }
3732                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
3733                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
3734                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
3735                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
3736                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
3737                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
3738                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
3739                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
3740                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
3741                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
3742                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
3743
3744                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
3745                                                                                                                         if(player[j].numclothes)
3746                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3747                                                                                                                         int templength;
3748                                                                                                                         templength=strlen(player[j].clothes[k]);
3749                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3750                                                                                                                         for(l=0;l<templength;l++)
3751                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
3752                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);
3753                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);
3754                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);
3755                                                                                                                         }
3756                                                                                                                         }
3757                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3758                                                                                                                         if(numpathpoints)
3759                                                                                                                         for(j=0;j<numpathpoints;j++){
3760                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
3761                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
3762                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
3763                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3764                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
3765                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3766                                                                                                                         }
3767                                                                                                                         }
3768
3769                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
3770                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
3771                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
3772
3773                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
3774
3775                                                                                                                         fclose(tfile);
3776                                                                                                                         donesomething=1;*/
3777                                                         }
3778                                                         /*
3779                                                         if(Compare(consoletext[0],"save ",0,4)){
3780                                                         mapname[0]=':';
3781                                                         mapname[1]='D';
3782                                                         mapname[2]='a';
3783                                                         mapname[3]='t';
3784                                                         mapname[4]='a';
3785                                                         mapname[5]=':';
3786                                                         mapname[6]='M';
3787                                                         mapname[7]='a';
3788                                                         mapname[8]='p';
3789                                                         mapname[9]='s';
3790                                                         mapname[10]=':';
3791                                                         for(j=5;j<consolechars[0];j++){
3792                                                         mapname[j-5+11]=consoletext[0][j];
3793                                                         }
3794                                                         mapname[consolechars[0]-5+11]='\0';
3795
3796                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3797                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3798                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3799
3800                                                         FILE                    *tfile;
3801                                                         tfile=fopen( mapname, "wb" );
3802                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
3803                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3804                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3805                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3806                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3807                                                         for(j=0;j<player[0].num_weapons;j++){
3808                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3809                                                         }
3810                                                         fwrite( &environment, 1, sizeof(int), tfile );
3811
3812                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3813                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
3814                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
3815                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
3816                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
3817
3818                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3819                                                         if(numplayers>1&&numplayers<maxplayers)
3820                                                         for(j=1;j<numplayers;j++){
3821                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
3822                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3823                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3824                                                         for(k=0;k<player[j].num_weapons;k++){
3825                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3826                                                         }
3827                                                         if(player[j].numwaypoints<30){
3828                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3829                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
3830                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3831                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3832                                                         }
3833                                                         else{
3834                                                         player[j].numwaypoints=0;
3835                                                         player[j].waypoint=0;
3836                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3837                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3838                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3839                                                         }
3840                                                         }
3841                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3842                                                         if(numpathpoints)
3843                                                         for(j=0;j<numpathpoints;j++){
3844                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
3845                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3846                                                         for(k=0;k<numpathpointconnect[j];k++){
3847                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3848                                                         }
3849                                                         }
3850                                                         fclose(tfile);
3851                                                         donesomething=1;
3852                                                         }*/
3853                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
3854                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
3855                                                                 donesomething=1;
3856                                                         }
3857                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
3858                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
3859                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
3860                                                         donesomething=1;
3861                                                         }*/
3862
3863                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
3864                                                                 for(j=6;j<consolechars[0];j++){
3865                                                                         mapname[j-6]=consoletext[0][j];
3866                                                                 }
3867
3868                                                                 tintr=atof(mapname);
3869
3870                                                                 donesomething=1;
3871                                                         }
3872
3873                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
3874                                                                 for(j=6;j<consolechars[0];j++){
3875                                                                         mapname[j-6]=consoletext[0][j];
3876                                                                 }
3877
3878                                                                 player[0].speedmult=atof(mapname);
3879
3880                                                                 donesomething=1;
3881                                                         }
3882
3883                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
3884                                                                 for(j=9;j<consolechars[0];j++){
3885                                                                         mapname[j-9]=consoletext[0][j];
3886                                                                 }
3887
3888                                                                 player[0].power=atof(mapname);
3889
3890                                                                 donesomething=1;
3891                                                         }
3892
3893                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
3894                                                                 for(j=13;j<consolechars[0];j++){
3895                                                                         mapname[j-13]=consoletext[0][j];
3896                                                                 }
3897
3898                                                                 viewdistance=atof(mapname)*100;
3899
3900                                                                 donesomething=1;
3901                                                         }
3902
3903                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
3904                                                                 for(j=10;j<consolechars[0];j++){
3905                                                                         mapname[j-10]=consoletext[0][j];
3906                                                                 }
3907
3908                                                                 fadestart=atof(mapname);
3909
3910                                                                 donesomething=1;
3911                                                         }
3912
3913                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
3914                                                                 for(j=6;j<consolechars[0];j++){
3915                                                                         mapname[j-6]=consoletext[0][j];
3916                                                                 }
3917
3918                                                                 player[0].power=atof(mapname);
3919
3920                                                                 donesomething=1;
3921                                                         }
3922
3923                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
3924                                                                 for(j=6;j<consolechars[0];j++){
3925                                                                         mapname[j-6]=consoletext[0][j];
3926                                                                 }
3927
3928                                                                 slomospeed=atof(mapname);
3929                                                                 slomo=1-slomo;
3930                                                                 slomodelay=1000;
3931
3932                                                                 donesomething=1;
3933                                                         }
3934
3935                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
3936                                                                 for(j=8;j<consolechars[0];j++){
3937                                                                         mapname[j-8]=consoletext[0][j];
3938                                                                 }
3939
3940                                                                 slomofreq=atoi(mapname);
3941
3942                                                                 donesomething=1;
3943                                                         }
3944
3945                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
3946                                                                 for(j=5;j<consolechars[0];j++){
3947                                                                         mapname[j-5]=consoletext[0][j];
3948                                                                 }
3949
3950                                                                 player[0].scale=atof(mapname)*.2;
3951
3952                                                                 donesomething=1;
3953                                                         }
3954
3955                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
3956                                                                 int closest=-1;
3957                                                                 float closestdist=-1;
3958                                                                 float distance;
3959                                                                 if(numplayers>1)
3960                                                                         for(i=1;i<numplayers;i++){
3961                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
3962                                                                                 if(closestdist==-1||distance<closestdist){
3963                                                                                         closestdist=distance;
3964                                                                                         closest=i;
3965                                                                                 }
3966                                                                         }
3967
3968                                                                         for(j=9;j<consolechars[0];j++){
3969                                                                                 mapname[j-9]=consoletext[0][j];
3970                                                                         }
3971
3972                                                                         player[closest].scale=atof(mapname)*.2;
3973
3974                                                                         donesomething=1;
3975                                                         }
3976
3977                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
3978                                                                 int startpoint;
3979                                                                 int alldone;
3980
3981                                                                 int closest=-1;
3982                                                                 float closestdist=-1;
3983                                                                 float distance;
3984                                                                 if(numplayers>1)
3985                                                                         for(i=1;i<numplayers;i++){
3986                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
3987                                                                                 if(closestdist==-1||distance<closestdist){
3988                                                                                         closestdist=distance;
3989                                                                                         closest=i;
3990                                                                                 }
3991                                                                         }
3992
3993                                                                         alldone=0;
3994                                                                         startpoint=15;
3995                                                                         j=startpoint;
3996                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3997                                                                                 mapname[j-startpoint]=consoletext[0][j];
3998                                                                                 j++;
3999                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4000                                                                         }
4001                                                                         mapname[j-startpoint]='\0';
4002
4003                                                                         headprop=atof(mapname);
4004
4005                                                                         j++;
4006                                                                         startpoint=j;
4007                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4008                                                                                 mapname[j-startpoint]=consoletext[0][j];
4009                                                                                 j++;
4010                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4011                                                                         }
4012                                                                         mapname[j-startpoint]='\0';
4013
4014                                                                         bodyprop=atof(mapname);
4015
4016                                                                         j++;
4017                                                                         startpoint=j;
4018                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4019                                                                                 mapname[j-startpoint]=consoletext[0][j];
4020                                                                                 j++;
4021                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4022                                                                         }
4023                                                                         mapname[j-startpoint]='\0';
4024
4025                                                                         armprop=atof(mapname);
4026
4027                                                                         j++;
4028                                                                         startpoint=j;
4029                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4030                                                                                 mapname[j-startpoint]=consoletext[0][j];
4031                                                                                 j++;
4032                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4033                                                                         }
4034                                                                         mapname[j-startpoint]='\0';
4035
4036                                                                         legprop=atof(mapname);
4037
4038                                                                         if(player[closest].creature==wolftype){
4039                                                                                 player[closest].proportionhead=1.1*headprop;
4040                                                                                 player[closest].proportionbody=1.1*bodyprop;
4041                                                                                 player[closest].proportionarms=1.1*armprop;
4042                                                                                 player[closest].proportionlegs=1.1*legprop;
4043                                                                         }
4044
4045                                                                         if(player[closest].creature==rabbittype){
4046                                                                                 player[closest].proportionhead=1.2*headprop;
4047                                                                                 player[closest].proportionbody=1.05*bodyprop;
4048                                                                                 player[closest].proportionarms=1.00*armprop;
4049                                                                                 player[closest].proportionlegs=1.1*legprop;
4050                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4051                                                                         }
4052
4053                                                                         donesomething=1;
4054                                                         }
4055
4056
4057                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4058                                                                 for(i=1;i<numplayers;i++){
4059                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4060                                                                 }
4061
4062                                                                 donesomething=1;
4063                                                         }
4064
4065                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4066                                                                 for(j=9;j<consolechars[0];j++){
4067                                                                         mapname[j-9]=consoletext[0][j];
4068                                                                 }
4069
4070                                                                 tutoriallevel=atoi(mapname);
4071
4072                                                                 donesomething=1;
4073                                                         }
4074
4075
4076                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4077                                                                 for(j=6;j<consolechars[0];j++){
4078                                                                         mapname[j-6]=consoletext[0][j];
4079                                                                 }
4080
4081                                                                 tintg=atof(mapname);
4082
4083                                                                 donesomething=1;
4084                                                         }
4085
4086                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4087                                                                 for(j=6;j<consolechars[0];j++){
4088                                                                         mapname[j-6]=consoletext[0][j];
4089                                                                 }
4090
4091                                                                 tintb=atof(mapname);
4092
4093                                                                 donesomething=1;
4094                                                         }
4095
4096                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4097                                                                 for(j=8;j<consolechars[0];j++){
4098                                                                         mapname[j-8]=consoletext[0][j];
4099                                                                 }
4100
4101                                                                 hostile=atoi(mapname);
4102
4103                                                                 donesomething=1;
4104                                                         }
4105
4106
4107                                                         if(Compare(consoletext[0],"type active ",0,11)){
4108                                                                 editoractive=typeactive;
4109
4110                                                                 donesomething=1;
4111                                                         }
4112
4113                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4114                                                                 indemo=1;
4115                                                                 hotspot[numhotspots]=player[0].coords;
4116                                                                 hotspotsize[numhotspots]=0;
4117                                                                 hotspottype[numhotspots]=-111;
4118                                                                 mapname[0]='\0';
4119                                                                 strcpy(hotspottext[numhotspots],"mapname");
4120                                                                 numhotspots++;
4121
4122                                                                 donesomething=1;
4123                                                         }
4124
4125                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4126                                                                 indemo=0;
4127                                                                 numhotspots--;
4128
4129                                                                 donesomething=1;
4130                                                         }
4131
4132                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4133                                                                 editoractive=typesitting;
4134
4135                                                                 donesomething=1;
4136                                                         }
4137
4138                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4139                                                                 editoractive=typesittingwall;
4140
4141                                                                 donesomething=1;
4142                                                         }
4143
4144                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4145                                                                 editoractive=typesleeping;
4146
4147                                                                 donesomething=1;
4148                                                         }
4149                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4150                                                                 editoractive=typedead1;
4151
4152                                                                 donesomething=1;
4153                                                         }
4154                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4155                                                                 editoractive=typedead2;
4156
4157                                                                 donesomething=1;
4158                                                         }
4159                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4160                                                                 editoractive=typedead3;
4161                                                                 donesomething=1;
4162                                                         }
4163                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4164                                                                 editoractive=typedead4;
4165
4166                                                                 donesomething=1;
4167                                                         }
4168
4169                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4170                                                                 editorpathtype=wpkeepwalking;
4171
4172                                                                 donesomething=1;
4173                                                         }
4174
4175                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4176                                                                 editorpathtype=wppause;
4177
4178                                                                 donesomething=1;
4179                                                         }
4180
4181                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4182                                                                 maptype=mapkilleveryone;
4183
4184                                                                 donesomething=1;
4185                                                         }
4186
4187                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4188                                                                 maptype=mapgosomewhere;
4189
4190                                                                 donesomething=1;
4191                                                         }
4192
4193                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4194                                                                 maptype=mapkillsomeone;
4195
4196                                                                 donesomething=1;
4197
4198                                                         }
4199
4200                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4201                                                                 maptype=mapkillmost;
4202
4203                                                                 donesomething=1;
4204
4205                                                         }
4206
4207                                                         if(Compare(consoletext[0],"hs ",0,2)){
4208                                                                 int startpoint;
4209                                                                 int alldone;
4210
4211                                                                 hotspot[numhotspots]=player[0].coords;
4212
4213                                                                 alldone=0;
4214                                                                 startpoint=3;
4215                                                                 j=startpoint;
4216                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4217                                                                         mapname[j-startpoint]=consoletext[0][j];
4218                                                                         j++;
4219                                                                         if(consoletext[0][j]=='\0')alldone=1;
4220                                                                 }
4221                                                                 mapname[j-startpoint]='\0';
4222
4223                                                                 hotspotsize[numhotspots]=atof(mapname);
4224
4225                                                                 j++;
4226                                                                 startpoint=j;
4227                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4228                                                                         mapname[j-startpoint]=consoletext[0][j];
4229                                                                         j++;
4230                                                                         if(consoletext[0][j]=='\0')alldone=1;
4231                                                                 }
4232                                                                 mapname[j-startpoint]='\0';
4233
4234                                                                 hotspottype[numhotspots]=atoi(mapname);
4235
4236                                                                 j++;
4237                                                                 startpoint=j;
4238                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4239                                                                         mapname[j-startpoint]=consoletext[0][j];
4240                                                                         j++;
4241                                                                         if(consoletext[0][j]=='\0')alldone=1;
4242                                                                 }
4243                                                                 mapname[j-startpoint]='\n';
4244                                                                 mapname[j-startpoint+1]='\0';
4245
4246                                                                 strcpy(hotspottext[numhotspots],mapname);
4247
4248                                                                 numhotspots++;
4249
4250                                                                 donesomething=1;
4251                                                         }
4252
4253                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4254                                                                 int startpoint;
4255                                                                 int alldone;
4256
4257                                                                 alldone=0;
4258                                                                 startpoint=9;
4259                                                                 j=startpoint;
4260                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4261                                                                         mapname[j-startpoint]=consoletext[0][j];
4262                                                                         j++;
4263                                                                         if(consoletext[0][j]=='\0')alldone=1;
4264                                                                 }
4265                                                                 mapname[j-startpoint]='\0';
4266                                                                 startpoint=j+1;
4267
4268                                                                 dialoguetype[numdialogues]=atoi(mapname);
4269
4270                                                                 mapname[0]=':';
4271                                                                 mapname[1]='D';
4272                                                                 mapname[2]='a';
4273                                                                 mapname[3]='t';
4274                                                                 mapname[4]='a';
4275                                                                 mapname[5]=':';
4276                                                                 mapname[6]='D';
4277                                                                 mapname[7]='i';
4278                                                                 mapname[8]='a';
4279                                                                 mapname[9]='l';
4280                                                                 mapname[10]='o';
4281                                                                 mapname[11]='g';
4282                                                                 mapname[12]='u';
4283                                                                 mapname[13]='e';
4284                                                                 mapname[14]='s';
4285                                                                 mapname[15]=':';
4286                                                                 for(j=startpoint;j<consolechars[0];j++){
4287                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4288                                                                 }
4289                                                                 mapname[consolechars[0]-startpoint+16]='.';
4290                                                                 mapname[consolechars[0]-startpoint+17]='t';
4291                                                                 mapname[consolechars[0]-startpoint+18]='x';
4292                                                                 mapname[consolechars[0]-startpoint+19]='t';
4293                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4294
4295                                                                 for(j=0;j<max_dialoguelength;j++){
4296                                                                         for(k=0;k<128;k++){
4297                                                                                 dialoguetext[numdialogues][j][k]='\0';
4298                                                                         }
4299                                                                         for(k=0;k<64;k++){
4300                                                                                 dialoguename[numdialogues][j][k]='\0';
4301                                                                         }
4302                                                                 }
4303
4304                                                                 ifstream ipstream(ConvertFileName(mapname));
4305                                                                 ipstream.ignore(256,':');
4306                                                                 ipstream >> numdialogueboxes[numdialogues];
4307                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4308                                                                         ipstream.ignore(256,':');
4309                                                                         ipstream.ignore(256,':');
4310                                                                         ipstream.ignore(256,' ');
4311                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4312                                                                         ipstream.ignore(256,':');
4313                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4314                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4315                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4316                                                                         ipstream.ignore(256,':');
4317                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4318                                                                         ipstream.ignore(256,':');
4319                                                                         ipstream.ignore(256,' ');
4320                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4321                                                                         for(j=0;j<128;j++){
4322                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4323                                                                         }
4324                                                                         ipstream.ignore(256,':');
4325                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4326                                                                 }
4327
4328                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4329                                                                         for(j=0;j<numplayers;j++){
4330                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4331                                                                         }
4332                                                                 }
4333                                                                 ipstream.close();
4334
4335                                                                 directing=1;
4336                                                                 indialogue=0;
4337                                                                 whichdialogue=numdialogues;
4338
4339
4340                                                                 numdialogues++;
4341
4342                                                                 donesomething=1;
4343                                                         }
4344
4345                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4346                                                                 int startpoint;
4347                                                                 int alldone;
4348                                                                 int whichdi;
4349
4350                                                                 alldone=0;
4351                                                                 startpoint=12;
4352                                                                 j=startpoint;
4353                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4354                                                                         mapname[j-startpoint]=consoletext[0][j];
4355                                                                         j++;
4356                                                                         if(consoletext[0][j]=='\0')alldone=1;
4357                                                                 }
4358                                                                 mapname[j-startpoint]='\0';
4359                                                                 startpoint=j+1;
4360
4361                                                                 whichdi=atoi(mapname);
4362
4363                                                                 mapname[0]=':';
4364                                                                 mapname[1]='D';
4365                                                                 mapname[2]='a';
4366                                                                 mapname[3]='t';
4367                                                                 mapname[4]='a';
4368                                                                 mapname[5]=':';
4369                                                                 mapname[6]='D';
4370                                                                 mapname[7]='i';
4371                                                                 mapname[8]='a';
4372                                                                 mapname[9]='l';
4373                                                                 mapname[10]='o';
4374                                                                 mapname[11]='g';
4375                                                                 mapname[12]='u';
4376                                                                 mapname[13]='e';
4377                                                                 mapname[14]='s';
4378                                                                 mapname[15]=':';
4379                                                                 for(j=startpoint;j<consolechars[0];j++){
4380                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4381                                                                 }
4382                                                                 mapname[consolechars[0]-startpoint+16]='.';
4383                                                                 mapname[consolechars[0]-startpoint+17]='t';
4384                                                                 mapname[consolechars[0]-startpoint+18]='x';
4385                                                                 mapname[consolechars[0]-startpoint+19]='t';
4386                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4387
4388                                                                 for(j=0;j<max_dialoguelength;j++){
4389                                                                         for(k=0;k<128;k++){
4390                                                                                 dialoguetext[whichdi][j][k]='\0';
4391                                                                         }
4392                                                                         for(k=0;k<64;k++){
4393                                                                                 dialoguename[whichdi][j][k]='\0';
4394                                                                         }
4395                                                                 }
4396
4397                                                                 ifstream ipstream(ConvertFileName(mapname));
4398                                                                 ipstream.ignore(256,':');
4399                                                                 ipstream >> numdialogueboxes[whichdi];
4400                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4401                                                                         ipstream.ignore(256,':');
4402                                                                         ipstream.ignore(256,':');
4403                                                                         ipstream.ignore(256,' ');
4404                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4405                                                                         ipstream.ignore(256,':');
4406                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4407                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4408                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4409                                                                         ipstream.ignore(256,':');
4410                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4411                                                                         ipstream.ignore(256,':');
4412                                                                         ipstream.ignore(256,' ');
4413                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4414                                                                         for(j=0;j<128;j++){
4415                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4416                                                                         }
4417                                                                         ipstream.ignore(256,':');
4418                                                                         ipstream >> dialogueboxsound[whichdi][i];
4419                                                                 }
4420
4421                                                                 ipstream.close();
4422
4423                                                                 donesomething=1;
4424                                                         }
4425
4426                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4427                                                                 int startpoint;
4428                                                                 int alldone;
4429                                                                 int whichdi;
4430
4431                                                                 alldone=0;
4432                                                                 startpoint=8;
4433                                                                 j=startpoint;
4434                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4435                                                                         mapname[j-startpoint]=consoletext[0][j];
4436                                                                         j++;
4437                                                                         if(consoletext[0][j]=='\0')alldone=1;
4438                                                                 }
4439                                                                 mapname[j-startpoint]='\0';
4440                                                                 dialoguetype[0]=atoi(mapname);
4441
4442                                                                 startpoint=j+1;
4443
4444                                                                 donesomething=1;
4445                                                         }
4446
4447
4448                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4449                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4450
4451                                                                 donesomething=1;
4452                                                         }
4453
4454                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4455                                                                 numdialogues--;
4456                                                                 if(numdialogues<0)numdialogues=0;
4457
4458                                                                 donesomething=1;
4459                                                         }
4460
4461                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4462                                                                 player[0].immobile=1;
4463                                                                 donesomething=1;
4464                                                         }
4465
4466                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4467                                                                 player[0].immobile=0;
4468                                                                 donesomething=1;
4469                                                         }
4470
4471                                                         if(Compare(consoletext[0],"play ",0,4)){
4472                                                                 int startpoint;
4473                                                                 int alldone;
4474
4475                                                                 alldone=0;
4476                                                                 startpoint=5;
4477                                                                 j=startpoint;
4478                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4479                                                                         mapname[j-startpoint]=consoletext[0][j];
4480                                                                         j++;
4481                                                                         if(consoletext[0][j]=='\0')alldone=1;
4482                                                                 }
4483                                                                 mapname[j-startpoint]='\0';
4484                                                                 startpoint=j+1;
4485
4486                                                                 whichdialogue=atoi(mapname);
4487
4488                                                                 if(numdialogues>whichdialogue){
4489                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4490                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4491                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4492                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4493                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4494                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4495                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4496                                                                         }
4497
4498                                                                         directing=0;
4499                                                                         indialogue=0;
4500
4501                                                                         donesomething=1;
4502
4503                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4504                                                                         float gLoc[3];
4505                                                                         float vel[3];
4506                                                                         XYZ temppos;
4507                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4508                                                                         temppos=temppos-viewer;
4509                                                                         Normalise(&temppos);
4510                                                                         temppos+=viewer;
4511
4512                                                                         gLoc[0]=temppos.x;
4513                                                                         gLoc[1]=temppos.y;
4514                                                                         gLoc[2]=temppos.z;
4515                                                                         vel[0]=0;
4516                                                                         vel[1]=0;
4517                                                                         vel[2]=0;
4518                                                                         int whichsoundplay;
4519                                                                         whichsoundplay=rabbitchitter;
4520                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4521                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4522                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4523                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4524                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4525                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4526                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4527                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4528                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4529                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4530                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4531                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4532                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4533                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4534                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4535                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4536                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4537                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4538                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4539                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4540                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4541                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
4542                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
4543                                                                         //}
4544                                                                 }
4545                                                         }
4546
4547
4548
4549
4550                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4551                                                                 numhotspots--;
4552                                                                 if(numhotspots<0)numhotspots=0;
4553                                                                 donesomething=1;
4554                                                         }
4555
4556
4557                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4558                                                                 int startpoint;
4559                                                                 int alldone;
4560
4561                                                                 alldone=0;
4562                                                                 startpoint=11;
4563                                                                 j=startpoint;
4564                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4565                                                                         mapname[j-startpoint]=consoletext[0][j];
4566                                                                         j++;
4567                                                                         if(consoletext[0][j]=='\0')alldone=1;
4568                                                                 }
4569                                                                 mapname[j-startpoint]='\0';
4570
4571                                                                 headprop=atof(mapname);
4572
4573                                                                 j++;
4574                                                                 startpoint=j;
4575                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4576                                                                         mapname[j-startpoint]=consoletext[0][j];
4577                                                                         j++;
4578                                                                         if(consoletext[0][j]=='\0')alldone=1;
4579                                                                 }
4580                                                                 mapname[j-startpoint]='\0';
4581
4582                                                                 bodyprop=atof(mapname);
4583
4584                                                                 j++;
4585                                                                 startpoint=j;
4586                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4587                                                                         mapname[j-startpoint]=consoletext[0][j];
4588                                                                         j++;
4589                                                                         if(consoletext[0][j]=='\0')alldone=1;
4590                                                                 }
4591                                                                 mapname[j-startpoint]='\0';
4592
4593                                                                 armprop=atof(mapname);
4594
4595                                                                 j++;
4596                                                                 startpoint=j;
4597                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4598                                                                         mapname[j-startpoint]=consoletext[0][j];
4599                                                                         j++;
4600                                                                         if(consoletext[0][j]=='\0')alldone=1;
4601                                                                 }
4602                                                                 mapname[j-startpoint]='\0';
4603
4604                                                                 legprop=atof(mapname);
4605
4606                                                                 if(player[0].creature==wolftype){
4607                                                                         player[0].proportionhead=1.1*headprop;
4608                                                                         player[0].proportionbody=1.1*bodyprop;
4609                                                                         player[0].proportionarms=1.1*armprop;
4610                                                                         player[0].proportionlegs=1.1*legprop;
4611                                                                 }
4612
4613                                                                 if(player[0].creature==rabbittype){
4614                                                                         player[0].proportionhead=1.2*headprop;
4615                                                                         player[0].proportionbody=1.05*bodyprop;
4616                                                                         player[0].proportionarms=1.00*armprop;
4617                                                                         player[0].proportionlegs=1.1*legprop;
4618                                                                         player[0].proportionlegs.y=1.05*legprop;
4619                                                                 }
4620
4621                                                                 donesomething=1;
4622                                                         }
4623
4624                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4625                                                                 for(i=0;i<numplayers;i++){
4626                                                                         if(i>0)player[i].immobile=1;
4627                                                                 }
4628                                                                 donesomething=1;
4629                                                         }
4630
4631
4632                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4633                                                                 player[0].armorhead=1;
4634                                                                 player[0].armorhigh=1;
4635                                                                 player[0].armorlow=1;
4636                                                                 player[0].protectionhead=1;
4637                                                                 player[0].protectionhigh=1;
4638                                                                 player[0].protectionlow=1;
4639                                                                 player[0].metalhead=1;
4640                                                                 player[0].metalhigh=1;
4641                                                                 player[0].metallow=1;
4642                                                                 player[0].power=1;
4643                                                                 player[0].speedmult=1;
4644                                                                 player[0].scale=1;
4645
4646                                                                 if(player[0].creature==wolftype){
4647                                                                         player[0].proportionhead=1.1;
4648                                                                         player[0].proportionbody=1.1;
4649                                                                         player[0].proportionarms=1.1;
4650                                                                         player[0].proportionlegs=1.1;
4651                                                                 }
4652
4653                                                                 if(player[0].creature==rabbittype){
4654                                                                         player[0].proportionhead=1.2;
4655                                                                         player[0].proportionbody=1.05;
4656                                                                         player[0].proportionarms=1.00;
4657                                                                         player[0].proportionlegs=1.1;
4658                                                                         player[0].proportionlegs.y=1.05;
4659                                                                 }
4660
4661                                                                 player[0].numclothes=0;
4662                                                                 LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
4663                                                                                 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4664
4665                                                                 editoractive=typeactive;
4666                                                                 player[0].immobile=0;
4667
4668
4669
4670                                                                 donesomething=1;
4671                                                         }
4672
4673                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4674                                                                 int startpoint;
4675                                                                 int alldone;
4676                                                                 alldone=0;
4677                                                                 startpoint=5;
4678                                                                 j=startpoint;
4679                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4680                                                                         mapname[j-startpoint]=consoletext[0][j];
4681                                                                         j++;
4682                                                                         if(consoletext[0][j]=='\0')alldone=1;
4683                                                                 }
4684                                                                 mapname[j-startpoint]='\0';
4685
4686                                                                 tintr=atof(mapname);
4687
4688                                                                 j++;
4689                                                                 startpoint=j;
4690                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4691                                                                         mapname[j-startpoint]=consoletext[0][j];
4692                                                                         j++;
4693                                                                         if(consoletext[0][j]=='\0')alldone=1;
4694                                                                 }
4695                                                                 mapname[j-startpoint]='\0';
4696
4697                                                                 tintg=atof(mapname);
4698
4699                                                                 j++;
4700                                                                 startpoint=j;
4701                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4702                                                                         mapname[j-startpoint]=consoletext[0][j];
4703                                                                         j++;
4704                                                                         if(consoletext[0][j]=='\0')alldone=1;
4705                                                                 }
4706                                                                 mapname[j-startpoint]='\0';
4707
4708                                                                 tintb=atof(mapname);
4709
4710                                                                 donesomething=1;
4711                                                         }
4712
4713                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
4714                                                                 int startpoint;
4715                                                                 int alldone;
4716                                                                 alldone=0;
4717                                                                 startpoint=9;
4718                                                                 j=startpoint;
4719                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4720                                                                         mapname[j-startpoint]=consoletext[0][j];
4721                                                                         j++;
4722                                                                         if(consoletext[0][j]=='\0')alldone=1;
4723                                                                 }
4724                                                                 mapname[j-startpoint]='\0';
4725
4726                                                                 skyboxr=atof(mapname);
4727
4728                                                                 j++;
4729                                                                 startpoint=j;
4730                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4731                                                                         mapname[j-startpoint]=consoletext[0][j];
4732                                                                         j++;
4733                                                                         if(consoletext[0][j]=='\0')alldone=1;
4734                                                                 }
4735                                                                 mapname[j-startpoint]='\0';
4736
4737                                                                 skyboxg=atof(mapname);
4738
4739                                                                 j++;
4740                                                                 startpoint=j;
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                                                                 skyboxb=atof(mapname);
4749
4750                                                                 skyboxlightr=skyboxr;
4751                                                                 skyboxlightg=skyboxg;
4752                                                                 skyboxlightb=skyboxb;
4753
4754                                                                 SetUpLighting();
4755
4756                                                                 //if(skyboxtexture){
4757                                                                 terrain.DoShadows();
4758                                                                 objects.DoShadows();
4759                                                                 /*}
4760                                                                 else terrain.DoLighting();
4761                                                                 */
4762                                                                 donesomething=1;
4763                                                         }
4764
4765                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
4766                                                                 int startpoint;
4767                                                                 int alldone;
4768                                                                 alldone=0;
4769                                                                 startpoint=10;
4770                                                                 j=startpoint;
4771                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4772                                                                         mapname[j-startpoint]=consoletext[0][j];
4773                                                                         j++;
4774                                                                         if(consoletext[0][j]=='\0')alldone=1;
4775                                                                 }
4776                                                                 mapname[j-startpoint]='\0';
4777
4778                                                                 skyboxlightr=atof(mapname);
4779
4780                                                                 j++;
4781                                                                 startpoint=j;
4782                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4783                                                                         mapname[j-startpoint]=consoletext[0][j];
4784                                                                         j++;
4785                                                                         if(consoletext[0][j]=='\0')alldone=1;
4786                                                                 }
4787                                                                 mapname[j-startpoint]='\0';
4788
4789                                                                 skyboxlightg=atof(mapname);
4790
4791                                                                 j++;
4792                                                                 startpoint=j;
4793                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4794                                                                         mapname[j-startpoint]=consoletext[0][j];
4795                                                                         j++;
4796                                                                         if(consoletext[0][j]=='\0')alldone=1;
4797                                                                 }
4798                                                                 mapname[j-startpoint]='\0';
4799
4800                                                                 skyboxlightb=atof(mapname);
4801
4802                                                                 SetUpLighting();
4803
4804                                                                 //if(skyboxtexture){
4805                                                                 terrain.DoShadows();
4806                                                                 objects.DoShadows();
4807                                                                 /*}
4808                                                                 else terrain.DoLighting();
4809                                                                 */
4810                                                                 donesomething=1;
4811                                                         }
4812
4813                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
4814                                                                 skyboxtexture=1-skyboxtexture;
4815
4816                                                                 SetUpLighting();
4817                                                                 //if(skyboxtexture){
4818                                                                 terrain.DoShadows();
4819                                                                 objects.DoShadows();
4820                                                                 /*}
4821                                                                 else terrain.DoLighting();
4822                                                                 */
4823                                                                 donesomething=1;
4824                                                         }
4825
4826                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
4827                                                                 int startpoint;
4828                                                                 int alldone;
4829                                                                 alldone=0;
4830                                                                 startpoint=11;
4831                                                                 j=startpoint;
4832                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4833                                                                         mapname[j-startpoint]=consoletext[0][j];
4834                                                                         j++;
4835                                                                         if(consoletext[0][j]=='\0')alldone=1;
4836                                                                 }
4837                                                                 mapname[j-startpoint]='\0';
4838
4839                                                                 player[0].protectionhead=atof(mapname);
4840
4841                                                                 j++;
4842                                                                 startpoint=j;
4843                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4844                                                                         mapname[j-startpoint]=consoletext[0][j];
4845                                                                         j++;
4846                                                                         if(consoletext[0][j]=='\0')alldone=1;
4847                                                                 }
4848                                                                 mapname[j-startpoint]='\0';
4849
4850                                                                 player[0].protectionhigh=atof(mapname);
4851
4852                                                                 j++;
4853                                                                 startpoint=j;
4854                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4855                                                                         mapname[j-startpoint]=consoletext[0][j];
4856                                                                         j++;
4857                                                                         if(consoletext[0][j]=='\0')alldone=1;
4858                                                                 }
4859                                                                 mapname[j-startpoint]='\0';
4860
4861                                                                 player[0].protectionlow=atof(mapname);
4862
4863                                                                 donesomething=1;
4864                                                         }
4865
4866                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
4867                                                                 int startpoint;
4868                                                                 int alldone;
4869                                                                 alldone=0;
4870                                                                 startpoint=6;
4871                                                                 j=startpoint;
4872                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4873                                                                         mapname[j-startpoint]=consoletext[0][j];
4874                                                                         j++;
4875                                                                         if(consoletext[0][j]=='\0')alldone=1;
4876                                                                 }
4877                                                                 mapname[j-startpoint]='\0';
4878
4879                                                                 player[0].armorhead=atof(mapname);
4880
4881                                                                 j++;
4882                                                                 startpoint=j;
4883                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4884                                                                         mapname[j-startpoint]=consoletext[0][j];
4885                                                                         j++;
4886                                                                         if(consoletext[0][j]=='\0')alldone=1;
4887                                                                 }
4888                                                                 mapname[j-startpoint]='\0';
4889
4890                                                                 player[0].armorhigh=atof(mapname);
4891
4892                                                                 j++;
4893                                                                 startpoint=j;
4894                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4895                                                                         mapname[j-startpoint]=consoletext[0][j];
4896                                                                         j++;
4897                                                                         if(consoletext[0][j]=='\0')alldone=1;
4898                                                                 }
4899                                                                 mapname[j-startpoint]='\0';
4900
4901                                                                 player[0].armorlow=atof(mapname);
4902
4903                                                                 donesomething=1;
4904                                                         }
4905
4906                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
4907                                                                 for(i=0;i<numplayers;i++){
4908                                                                         player[i].protectionhead=1.0;
4909                                                                         player[i].protectionhigh=1.0;
4910                                                                         player[i].protectionlow=1.0;
4911                                                                         player[i].armorhead=1.0;
4912                                                                         player[i].armorhigh=1.0;
4913                                                                         player[i].armorlow=1.0;
4914                                                                 }
4915
4916                                                                 donesomething=1;
4917                                                         }
4918
4919                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
4920                                                                 int closest=-1;
4921                                                                 float closestdist=-1;
4922                                                                 float distance;
4923                                                                 if(numplayers>1)
4924                                                                         for(i=1;i<numplayers;i++){
4925                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4926                                                                                 if(closestdist==-1||distance<closestdist){
4927                                                                                         closestdist=distance;
4928                                                                                         closest=i;
4929                                                                                 }
4930                                                                         }
4931
4932                                                                         int startpoint;
4933                                                                         int alldone;
4934                                                                         alldone=0;
4935                                                                         startpoint=15;
4936                                                                         j=startpoint;
4937                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4938                                                                                 mapname[j-startpoint]=consoletext[0][j];
4939                                                                                 j++;
4940                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4941                                                                         }
4942                                                                         mapname[j-startpoint]='\0';
4943
4944                                                                         player[closest].protectionhead=atof(mapname);
4945
4946                                                                         j++;
4947                                                                         startpoint=j;
4948                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4949                                                                                 mapname[j-startpoint]=consoletext[0][j];
4950                                                                                 j++;
4951                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4952                                                                         }
4953                                                                         mapname[j-startpoint]='\0';
4954
4955                                                                         player[closest].protectionhigh=atof(mapname);
4956
4957                                                                         j++;
4958                                                                         startpoint=j;
4959                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4960                                                                                 mapname[j-startpoint]=consoletext[0][j];
4961                                                                                 j++;
4962                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4963                                                                         }
4964                                                                         mapname[j-startpoint]='\0';
4965
4966                                                                         player[closest].protectionlow=atof(mapname);
4967
4968                                                                         donesomething=1;
4969                                                         }
4970
4971                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
4972                                                                 int closest=-1;
4973                                                                 float closestdist=-1;
4974                                                                 float distance;
4975                                                                 if(numplayers>1)
4976                                                                         for(i=1;i<numplayers;i++){
4977                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4978                                                                                 if(closestdist==-1||distance<closestdist){
4979                                                                                         closestdist=distance;
4980                                                                                         closest=i;
4981                                                                                 }
4982                                                                         }
4983                                                                         int startpoint;
4984                                                                         int alldone;
4985                                                                         alldone=0;
4986                                                                         startpoint=10;
4987                                                                         j=startpoint;
4988                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4989                                                                                 mapname[j-startpoint]=consoletext[0][j];
4990                                                                                 j++;
4991                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4992                                                                         }
4993                                                                         mapname[j-startpoint]='\0';
4994
4995                                                                         player[closest].armorhead=atof(mapname);
4996
4997                                                                         j++;
4998                                                                         startpoint=j;
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[closest].armorhigh=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[closest].armorlow=atof(mapname);
5018
5019                                                                         donesomething=1;
5020                                                         }
5021
5022
5023                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5024                                                                 int startpoint;
5025                                                                 int alldone;
5026                                                                 alldone=0;
5027                                                                 startpoint=6;
5028                                                                 j=startpoint;
5029                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5030                                                                         mapname[j-startpoint]=consoletext[0][j];
5031                                                                         j++;
5032                                                                         if(consoletext[0][j]=='\0')alldone=1;
5033                                                                 }
5034                                                                 mapname[j-startpoint]='\0';
5035
5036                                                                 player[0].metalhead=atof(mapname);
5037
5038                                                                 j++;
5039                                                                 startpoint=j;
5040                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5041                                                                         mapname[j-startpoint]=consoletext[0][j];
5042                                                                         j++;
5043                                                                         if(consoletext[0][j]=='\0')alldone=1;
5044                                                                 }
5045                                                                 mapname[j-startpoint]='\0';
5046
5047                                                                 player[0].metalhigh=atof(mapname);
5048
5049                                                                 j++;
5050                                                                 startpoint=j;
5051                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5052                                                                         mapname[j-startpoint]=consoletext[0][j];
5053                                                                         j++;
5054                                                                         if(consoletext[0][j]=='\0')alldone=1;
5055                                                                 }
5056
5057                                                                 mapname[j-startpoint]='\0';
5058
5059                                                                 player[0].metallow=atof(mapname);
5060
5061                                                                 donesomething=1;
5062                                                         }
5063
5064                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5065                                                                 int closest=-1;
5066                                                                 float closestdist=-1;
5067                                                                 float distance;
5068                                                                 if(numplayers>1)
5069                                                                         for(i=1;i<numplayers;i++){
5070                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5071                                                                                 if(closestdist==-1||distance<closestdist){
5072                                                                                         closestdist=distance;
5073                                                                                         closest=i;
5074                                                                                 }
5075                                                                         }
5076                                                                         player[closest].numclothes=0;
5077                                                                         LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
5078                                                                                         &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5079
5080                                                                         donesomething=1;
5081                                                         }
5082
5083                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5084                                                                 int closest=0;
5085
5086                                                                 player[closest].numclothes=0;
5087                                                                 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
5088                                                                                 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5089                                                                 donesomething=1;
5090                                                         }
5091
5092                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5093                                                                 mapname[0]=':';
5094                                                                 mapname[1]='D';
5095                                                                 mapname[2]='a';
5096                                                                 mapname[3]='t';
5097                                                                 mapname[4]='a';
5098                                                                 mapname[5]=':';
5099                                                                 mapname[6]='T';
5100                                                                 mapname[7]='e';
5101                                                                 mapname[8]='x';
5102                                                                 mapname[9]='t';
5103                                                                 mapname[10]='u';
5104                                                                 mapname[11]='r';
5105                                                                 mapname[12]='e';
5106                                                                 mapname[13]='s';
5107                                                                 mapname[14]=':';
5108                                                                 for(j=8;j<consolechars[0];j++){
5109                                                                         mapname[j-8+15]=consoletext[0][j];
5110                                                                 }
5111                                                                 mapname[consolechars[0]-8+15]='.';
5112                                                                 mapname[consolechars[0]-8+16]='p';
5113                                                                 mapname[consolechars[0]-8+17]='n';
5114                                                                 mapname[consolechars[0]-8+18]='g';
5115                                                                 mapname[consolechars[0]-8+19]='\0';
5116
5117                                                                 //:Data:Textures:Pants.png
5118
5119                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5120                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5121                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5122                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5123                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5124                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5125                                                                         player[0].numclothes++;
5126                                                                 }
5127
5128                                                                 donesomething=1;
5129                                                         }
5130
5131                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5132                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5133
5134                                                                 donesomething=1;
5135                                                         }
5136
5137                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5138                                                                 cellophane=1-cellophane;
5139
5140                                                                 if(cellophane){
5141                                                                         for(i=0;i<numplayers;i++){
5142                                                                                 player[i].proportionhead.z=0;
5143                                                                                 player[i].proportionbody.z=0;
5144                                                                                 player[i].proportionarms.z=0;
5145                                                                                 player[i].proportionlegs.z=0;
5146                                                                         }
5147                                                                 }
5148
5149                                                                 if(!cellophane){
5150                                                                         for(i=0;i<numplayers;i++){
5151                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5152                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5153                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5154                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5155                                                                         }
5156                                                                 }
5157
5158                                                                 donesomething=1;
5159                                                         }
5160
5161                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5162                                                                 mapname[0]=':';
5163                                                                 mapname[1]='D';
5164                                                                 mapname[2]='a';
5165                                                                 mapname[3]='t';
5166                                                                 mapname[4]='a';
5167                                                                 mapname[5]=':';
5168                                                                 mapname[6]='T';
5169                                                                 mapname[7]='e';
5170                                                                 mapname[8]='x';
5171                                                                 mapname[9]='t';
5172                                                                 mapname[10]='u';
5173                                                                 mapname[11]='r';
5174                                                                 mapname[12]='e';
5175                                                                 mapname[13]='s';
5176                                                                 mapname[14]=':';
5177                                                                 for(j=12;j<consolechars[0];j++){
5178                                                                         mapname[j-12+15]=consoletext[0][j];
5179                                                                 }
5180                                                                 mapname[consolechars[0]-12+15]='.';
5181                                                                 mapname[consolechars[0]-12+16]='p';
5182                                                                 mapname[consolechars[0]-12+17]='n';
5183                                                                 mapname[consolechars[0]-12+18]='g';
5184                                                                 mapname[consolechars[0]-12+19]='\0';
5185
5186                                                                 //:Data:Textures:Pants.png
5187                                                                 int closest=-1;
5188                                                                 float closestdist=-1;
5189                                                                 float distance;
5190                                                                 if(numplayers>1)
5191                                                                         for(i=1;i<numplayers;i++){
5192                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5193                                                                                 if(closestdist==-1||distance<closestdist){
5194                                                                                         closestdist=distance;
5195                                                                                         closest=i;
5196                                                                                 }
5197                                                                         }
5198
5199                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5200                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5201                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5202                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5203                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5204                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5205                                                                                 player[closest].numclothes++;
5206                                                                         }
5207
5208                                                                         donesomething=1;
5209                                                         }
5210
5211                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5212                                                                 player[0].skeleton.id=0;
5213                                                                 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);
5214                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5215                                                                 player[0].creature=rabbittype;
5216                                                                 player[0].scale=.2;
5217
5218                                                                 player[0].proportionhead=1.2;
5219                                                                 player[0].proportionbody=1.05;
5220                                                                 player[0].proportionarms=1.00;
5221                                                                 player[0].proportionlegs=1.1;
5222                                                                 player[0].proportionlegs.y=1.05;
5223                                                                 player[0].headless=0;
5224
5225                                                                 player[0].damagetolerance=200;
5226
5227                                                                 donesomething=1;
5228                                                         }
5229                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5230                                                                 player[0].skeleton.id=0;
5231                                                                 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);
5232                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5233                                                                 player[0].creature=wolftype;
5234
5235                                                                 player[0].proportionhead=1.1;
5236                                                                 player[0].proportionbody=1.1;
5237                                                                 player[0].proportionarms=1.1;
5238                                                                 player[0].proportionlegs=1.1;
5239                                                                 player[0].proportionlegs.y=1.1;
5240                                                                 player[0].scale=.23;
5241
5242                                                                 player[0].damagetolerance=300;
5243
5244                                                                 donesomething=1;
5245                                                         }
5246                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5247                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5248                                                         donesomething=1;
5249                                                         }
5250                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5251                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5252                                                         donesomething=1;
5253                                                         }
5254                                                         if(Compare(consoletext[0],"david ",0,5)){
5255                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5256                                                         donesomething=1;
5257                                                         }*/
5258                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5259                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5260                                                                 donesomething=1;
5261                                                         }
5262                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5263                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5264                                                                 donesomething=1;
5265                                                         }
5266                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5267                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5268                                                                 donesomething=1;
5269                                                         }/*
5270                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5271                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5272                                                          donesomething=1;
5273                                                          }*/
5274                                                         if(Compare(consoletext[0],"white ",0,5)){
5275                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5276                                                                 donesomething=1;
5277                                                         }
5278                                                         if(Compare(consoletext[0],"brown ",0,5)){
5279                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5280                                                                 donesomething=1;
5281                                                         }
5282                                                         if(Compare(consoletext[0],"black ",0,5)){
5283                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5284                                                                 donesomething=1;
5285                                                         }
5286                                                         if(consolechars[0]>0){
5287                                                                 for(k=14;k>=1;k--){
5288                                                                         for(j=0;j<255;j++){
5289                                                                                 consoletext[k][j]=consoletext[k-1][j];
5290                                                                         }
5291                                                                         consolechars[k]=consolechars[k-1];
5292                                                                 }
5293                                                                 for(j=0;j<255;j++){
5294                                                                         consoletext[0][j]=' ';
5295                                                                 }
5296                                                                 consolechars[0]=0;
5297                                                                 consoleselected=0;
5298
5299                                                                 if(!donesomething){
5300                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
5301                                                                         OPENAL_SetVolume(channels[consolefailsound], 256);
5302                                                                         OPENAL_SetPaused(channels[consolefailsound], false);
5303                                                                 }
5304                                                         }
5305                                                 }
5306                                         }
5307                                         togglekey[i]=1;
5308                                 }
5309                                 else {
5310                                         togglekey[i]=0;
5311                                         togglekeydelay[i]=0;
5312                                 }
5313                         }
5314
5315                         consoleblinkdelay-=multiplier;
5316                         if(consoleblinkdelay<=0){
5317                                 consoleblinkdelay=.3;
5318                                 consoleblink=1-consoleblink;
5319                         }
5320                 }
5321
5322                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5323                         tryquit=1;
5324                         if(mainmenu==3){
5325                                 if(newdetail>2)newdetail=detail;
5326                                 if(newdetail<0)newdetail=detail;
5327                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5328                                 if(newscreenheight<0)newscreenheight=screenheight;
5329
5330                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5331                                 opstream << "Screenwidth:\n";
5332                                 opstream << newscreenwidth;
5333                                 opstream << "\nScreenheight:\n";
5334                                 opstream << newscreenheight;
5335                                 opstream << "\nMouse sensitivity:\n";
5336                                 opstream << usermousesensitivity;
5337                                 opstream << "\nBlur(0,1):\n";
5338                                 opstream << ismotionblur;
5339                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5340                                 opstream << newdetail;
5341                                 opstream << "\nFloating jump:\n";
5342                                 opstream << floatjump;
5343                                 opstream << "\nMouse jump:\n";
5344                                 opstream << mousejump;
5345                                 opstream << "\nAmbient sound:\n";
5346                                 opstream << ambientsound;
5347                                 opstream << "\nBlood (0,1,2):\n";
5348                                 opstream << bloodtoggle;
5349                                 opstream << "\nAuto slomo:\n";
5350                                 opstream << autoslomo;
5351                                 opstream << "\nFoliage:\n";
5352                                 opstream << foliage;
5353                                 opstream << "\nMusic:\n";
5354                                 opstream << musictoggle;
5355                                 opstream << "\nTrilinear:\n";
5356                                 opstream << trilinear;
5357                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5358                                 opstream << decals;
5359                                 opstream << "\nInvert mouse:\n";
5360                                 opstream << invertmouse;
5361                                 opstream << "\nGamespeed:\n";
5362                                 if(oldgamespeed==0)oldgamespeed=1;
5363                                 opstream << oldgamespeed;
5364                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5365                                 opstream << difficulty;
5366                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5367                                 opstream << damageeffects;
5368                                 opstream << "\nText:\n";
5369                                 opstream << texttoggle;
5370                                 opstream << "\nDebug:\n";
5371                                 opstream << debugmode;
5372                                 opstream << "\nVBL Sync:\n";
5373                                 opstream << vblsync;
5374                                 opstream << "\nShow Points:\n";
5375                                 opstream << showpoints;
5376                                 opstream << "\nAlways Blur:\n";
5377                                 opstream << alwaysblur;
5378                                 opstream << "\nImmediate mode (turn on on G5):\n";
5379                                 opstream << immediate;
5380                                 opstream << "\nVelocity blur:\n";
5381                                 opstream << velocityblur;
5382                             opstream << "\nVolume:\n";
5383                         opstream << volume;
5384                                 opstream << "\nForward key:\n";
5385                                 opstream << KeyToChar(forwardkey);
5386                                 opstream << "\nBack key:\n";
5387                                 opstream << KeyToChar(backkey);
5388                                 opstream << "\nLeft key:\n";
5389                                 opstream << KeyToChar(leftkey);
5390                                 opstream << "\nRight key:\n";
5391                                 opstream << KeyToChar(rightkey);
5392                                 opstream << "\nJump key:\n";
5393                                 opstream << KeyToChar(jumpkey);
5394                                 opstream << "\nCrouch key:\n";
5395                                 opstream << KeyToChar(crouchkey);
5396                                 opstream << "\nDraw key:\n";
5397                                 opstream << KeyToChar(drawkey);
5398                                 opstream << "\nThrow key:\n";
5399                                 opstream << KeyToChar(throwkey);
5400                                 opstream << "\nAttack key:\n";
5401                                 opstream << KeyToChar(attackkey);
5402                                 opstream << "\nChat key:\n";
5403                                 opstream << KeyToChar(chatkey);
5404                                 opstream.close();
5405                         }
5406                 }
5407
5408                 static int oldwinfreeze;
5409                 if(winfreeze&&!oldwinfreeze){
5410                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5411                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
5412                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
5413                         OPENAL_SetPaused(channels[consolesuccesssound], false);
5414                 }
5415                 if(winfreeze==0)oldwinfreeze=winfreeze;
5416                 else oldwinfreeze++;
5417
5418                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5419                         if(winfreeze)winfreeze=0;
5420                         oldjumpkeydown=1;
5421                 }
5422                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5423                         if(winfreeze){
5424                                 mainmenu=9;
5425                                 gameon=0;
5426                         }
5427                 }
5428                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5429                         oldjumpkeydown=1;
5430                 }
5431                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5432
5433                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5434
5435                         static bool oldbuttondialogue;
5436
5437                         if(indialogue!=-1)talkdelay=1;
5438                         talkdelay-=multiplier;
5439
5440                         if(talkdelay<=0)
5441                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5442                                         for(i=0;i<numdialogues;i++){
5443                                                 int realdialoguetype;
5444                                                 bool special;
5445                                                 if(dialoguetype[i]>49){
5446                                                         realdialoguetype=dialoguetype[i]-50;
5447                                                         special=1;
5448                                                 }
5449                                                 else if(dialoguetype[i]>39){
5450                                                         realdialoguetype=dialoguetype[i]-40;
5451                                                         special=1;
5452                                                 }
5453                                                 else if(dialoguetype[i]>29){
5454                                                         realdialoguetype=dialoguetype[i]-30;
5455                                                         special=1;
5456                                                 }
5457                                                 else if(dialoguetype[i]>19){
5458                                                         realdialoguetype=dialoguetype[i]-20;
5459                                                         special=1;
5460                                                 }
5461                                                 else if(dialoguetype[i]>9){
5462                                                         realdialoguetype=dialoguetype[i]-10;
5463                                                         special=1;
5464                                                 }
5465                                                 else {
5466                                                         realdialoguetype=dialoguetype[i];
5467                                                         special=0;
5468                                                 }
5469                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5470                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5471                                                                 whichdialogue=i;
5472                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5473                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5474                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5475                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5476                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5477                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5478                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5479                                                                 }
5480                                                                 directing=0;
5481                                                                 indialogue=0;
5482                                                                 dialoguetime=0;
5483                                                                 dialoguegonethrough[i]++;
5484                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5485                                                                         static float gLoc[3];
5486                                                                         static float vel[3];
5487                                                                         XYZ temppos;
5488                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5489                                                                         temppos=temppos-viewer;
5490                                                                         Normalise(&temppos);
5491                                                                         temppos+=viewer;
5492
5493                                                                         gLoc[0]=temppos.x;
5494                                                                         gLoc[1]=temppos.y;
5495                                                                         gLoc[2]=temppos.z;vel[0]=0;
5496                                                                         vel[1]=0;
5497                                                                         vel[2]=0;
5498                                                                         int whichsoundplay;
5499                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5500                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5501                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5502                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5503                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5504                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5505                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5506                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5507                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5508                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5509                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5510                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5511                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5512                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5513                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5514                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5515                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5516                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5517                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5518                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5519                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
5520                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5521                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
5522                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
5523                                                                 }
5524                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5525                                                         }
5526                                                 }
5527                                         }
5528
5529                                         windvar+=multiplier;
5530                                         smoketex+=multiplier;
5531                                         tutorialstagetime+=multiplier;
5532
5533                                         static float hotspotvisual[40];
5534                                         if(numhotspots){
5535                                                 XYZ hotspotsprite;
5536                                                 if(editorenabled)
5537                                                         for(i=0;i<numhotspots;i++)
5538                                                                 hotspotvisual[i]-=multiplier/320;
5539
5540                                                 for(i=0;i<numhotspots;i++){
5541                                                         //if(hotspottype[i]<=10)
5542                                                         while(hotspotvisual[i]<0){
5543                                                                 hotspotsprite=0;
5544                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5545                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5546                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5547                                                                 hotspotsprite+=hotspot[i];
5548                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5549                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5550                                                         }
5551                                                 }
5552
5553                                                 for(i=0;i<numhotspots;i++){
5554                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5555                                                                 hotspot[i]=player[hotspottype[i]].coords;
5556                                                         }
5557                                                 }
5558                                         }
5559
5560                                         //Tutorial
5561                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5562                                                 tutorialstage++;
5563                                                 tutorialsuccess=0;
5564                                                 if(tutorialstage<=1){
5565                                                         canattack=0;
5566                                                         cananger=0;
5567                                                         reversaltrain=0;
5568                                                 }
5569                                                 if(tutorialstage==1){
5570                                                         tutorialmaxtime=5;
5571                                                 }
5572                                                 if(tutorialstage==2){
5573                                                         tutorialmaxtime=2;
5574                                                 }
5575                                                 if(tutorialstage==3){
5576                                                         tutorialmaxtime=600;
5577                                                 }
5578                                                 if(tutorialstage==4){
5579                                                         tutorialmaxtime=1000;
5580                                                 }
5581                                                 if(tutorialstage==5){
5582                                                         tutorialmaxtime=600;
5583                                                 }
5584                                                 if(tutorialstage==6){
5585                                                         tutorialmaxtime=600;
5586                                                 }
5587                                                 if(tutorialstage==7){
5588                                                         tutorialmaxtime=600;
5589                                                 }
5590                                                 if(tutorialstage==8){
5591                                                         tutorialmaxtime=600;
5592                                                 }
5593                                                 if(tutorialstage==9){
5594                                                         tutorialmaxtime=600;
5595                                                 }
5596                                                 if(tutorialstage==10){
5597                                                         tutorialmaxtime=2;
5598                                                 }
5599                                                 if(tutorialstage==11){
5600                                                         tutorialmaxtime=1000;
5601                                                 }
5602                                                 if(tutorialstage==12){
5603                                                         tutorialmaxtime=1000;
5604                                                 }
5605                                                 if(tutorialstage==13){
5606                                                         tutorialmaxtime=2;
5607                                                 }
5608                                                 if(tutorialstage==14){
5609                                                         tutorialmaxtime=3;
5610
5611                                                         XYZ temp,temp2;
5612
5613                                                         temp.x=1011;
5614                                                         temp.y=84;
5615                                                         temp.z=491;
5616                                                         temp2.x=1025;
5617                                                         temp2.y=75;
5618                                                         temp2.z=447;
5619
5620                                                         player[1].coords=(temp+temp2)/2;
5621
5622                                                         float gLoc[3];
5623                                                         float vel[3];
5624                                                         gLoc[0]=player[1].coords.x;
5625                                                         gLoc[1]=player[1].coords.y;
5626                                                         gLoc[2]=player[1].coords.z;
5627                                                         vel[0]=0;
5628                                                         vel[1]=0;
5629                                                         vel[2]=0;
5630                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5631                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5632                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5633                                                         OPENAL_SetPaused(channels[fireendsound], false);
5634
5635                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5636                                                                 if(Random()%2==0){
5637                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5638                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5639                                                                         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;
5640                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5641                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5642                                                                 }
5643                                                         }
5644
5645                                                 }
5646                                                 if(tutorialstage==15){
5647                                                         tutorialmaxtime=500;
5648                                                 }
5649                                                 if(tutorialstage==16){
5650                                                         tutorialmaxtime=500;
5651                                                 }
5652                                                 if(tutorialstage==17){
5653                                                         tutorialmaxtime=500;
5654                                                 }
5655                                                 if(tutorialstage==18){
5656                                                         tutorialmaxtime=500;
5657                                                 }
5658                                                 if(tutorialstage==19){
5659                                                         tutorialstage=20;
5660                                                         //tutorialmaxtime=500;
5661                                                 }
5662                                                 if(tutorialstage==20){
5663                                                         tutorialmaxtime=500;
5664                                                 }
5665                                                 if(tutorialstage==21){
5666                                                         tutorialmaxtime=500;
5667                                                         if(bonus==cannon){
5668                                                                 bonus=Slicebonus;
5669                                                                 againbonus=1;
5670                                                         }
5671                                                         else againbonus=0;
5672                                                 }
5673                                                 if(tutorialstage==22){
5674                                                         tutorialmaxtime=500;
5675                                                 }
5676                                                 if(tutorialstage==23){
5677                                                         tutorialmaxtime=500;
5678                                                 }
5679                                                 if(tutorialstage==24){
5680                                                         tutorialmaxtime=500;
5681                                                 }
5682                                                 if(tutorialstage==25){
5683                                                         tutorialmaxtime=500;
5684                                                 }
5685                                                 if(tutorialstage==26){
5686                                                         tutorialmaxtime=2;
5687                                                 }
5688                                                 if(tutorialstage==27){
5689                                                         tutorialmaxtime=4;
5690                                                         reversaltrain=1;
5691                                                         cananger=1;
5692                                                         player[1].aitype=attacktypecutoff;
5693                                                 }
5694                                                 if(tutorialstage==28){
5695                                                         tutorialmaxtime=400;
5696                                                 }
5697                                                 if(tutorialstage==29){
5698                                                         tutorialmaxtime=400;
5699                                                         player[0].escapednum=0;
5700                                                 }
5701                                                 if(tutorialstage==30){
5702                                                         tutorialmaxtime=4;
5703                                                         reversaltrain=0;
5704                                                         cananger=0;
5705                                                         player[1].aitype=passivetype;
5706                                                 }
5707                                                 if(tutorialstage==31){
5708                                                         tutorialmaxtime=13;
5709                                                 }
5710                                                 if(tutorialstage==32){
5711                                                         tutorialmaxtime=8;
5712                                                 }
5713                                                 if(tutorialstage==33){
5714                                                         tutorialmaxtime=400;
5715                                                         cananger=1;
5716                                                         canattack=1;
5717                                                         player[1].aitype=attacktypecutoff;
5718                                                 }
5719                                                 if(tutorialstage==34){
5720                                                         tutorialmaxtime=400;
5721                                                 }
5722                                                 if(tutorialstage==35){
5723                                                         tutorialmaxtime=400;
5724                                                 }
5725                                                 if(tutorialstage==36){
5726                                                         tutorialmaxtime=2;
5727                                                         reversaltrain=0;
5728                                                         cananger=0;
5729                                                         player[1].aitype=passivetype;
5730                                                 }
5731                                                 if(tutorialstage==37){
5732                                                         damagedealt=0;
5733                                                         damagetaken=0;
5734                                                         tutorialmaxtime=50;
5735                                                         cananger=1;
5736                                                         canattack=1;
5737                                                         player[1].aitype=attacktypecutoff;
5738                                                 }
5739                                                 if(tutorialstage==38){
5740                                                         tutorialmaxtime=4;
5741                                                         canattack=0;
5742                                                         cananger=0;
5743                                                         player[1].aitype=passivetype;
5744                                                 }
5745                                                 if(tutorialstage==39){
5746                                                         XYZ temp,temp2;
5747
5748                                                         temp.x=1011;
5749                                                         temp.y=84;
5750                                                         temp.z=491;
5751                                                         temp2.x=1025;
5752                                                         temp2.y=75;
5753                                                         temp2.z=447;
5754
5755
5756                                                         weapons.owner[weapons.numweapons]=-1;
5757                                                         weapons.type[weapons.numweapons]=knife;
5758                                                         weapons.damage[weapons.numweapons]=0;
5759                                                         weapons.mass[weapons.numweapons]=1;
5760                                                         weapons.tipmass[weapons.numweapons]=1.2;
5761                                                         weapons.length[weapons.numweapons]=.25;
5762                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
5763                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
5764
5765                                                         weapons.velocity[weapons.numweapons]=0.1;
5766                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
5767                                                         weapons.missed[weapons.numweapons]=1;
5768                                                         weapons.hitsomething[weapons.numweapons]=0;
5769                                                         weapons.freetime[weapons.numweapons]=0;
5770                                                         weapons.firstfree[weapons.numweapons]=1;
5771                                                         weapons.physics[weapons.numweapons]=1;
5772
5773                                                         weapons.numweapons++;
5774                                                 }
5775                                                 if(tutorialstage==40){
5776                                                         tutorialmaxtime=300;
5777                                                 }
5778                                                 if(tutorialstage==41){
5779                                                         tutorialmaxtime=300;
5780                                                 }
5781                                                 if(tutorialstage==42){
5782                                                         tutorialmaxtime=8;
5783                                                 }
5784                                                 if(tutorialstage==43){
5785                                                         tutorialmaxtime=300;
5786                                                 }
5787                                                 if(tutorialstage==44){
5788                                                         weapons.owner[0]=1;
5789                                                         player[0].weaponactive=-1;
5790                                                         player[0].num_weapons=0;
5791                                                         player[1].weaponactive=0;
5792                                                         player[1].num_weapons=1;
5793                                                         player[1].weaponids[0]=0;
5794
5795                                                         cananger=1;
5796                                                         canattack=1;
5797                                                         player[1].aitype=attacktypecutoff;
5798
5799                                                         tutorialmaxtime=300;
5800                                                 }
5801                                                 if(tutorialstage==45){
5802                                                         weapons.owner[0]=1;
5803                                                         player[0].weaponactive=-1;
5804                                                         player[0].num_weapons=0;
5805                                                         player[1].weaponactive=0;
5806                                                         player[1].num_weapons=1;
5807                                                         player[1].weaponids[0]=0;
5808
5809                                                         tutorialmaxtime=300;
5810                                                 }
5811                                                 if(tutorialstage==46){
5812                                                         weapons.owner[0]=1;
5813                                                         player[0].weaponactive=-1;
5814                                                         player[0].num_weapons=0;
5815                                                         player[1].weaponactive=0;
5816                                                         player[1].num_weapons=1;
5817                                                         player[1].weaponids[0]=0;
5818
5819                                                         weapons.type[0]=sword;
5820
5821                                                         tutorialmaxtime=300;
5822                                                 }
5823
5824                                                 if(tutorialstage==47){
5825                                                         tutorialmaxtime=10;
5826
5827                                                         XYZ temp,temp2;
5828
5829                                                         temp.x=1011;
5830                                                         temp.y=84;
5831                                                         temp.z=491;
5832                                                         temp2.x=1025;
5833                                                         temp2.y=75;
5834                                                         temp2.z=447;
5835
5836                                                         weapons.owner[weapons.numweapons]=-1;
5837                                                         weapons.type[weapons.numweapons]=sword;
5838                                                         weapons.damage[weapons.numweapons]=0;
5839                                                         weapons.mass[weapons.numweapons]=1;
5840                                                         weapons.tipmass[weapons.numweapons]=1.2;
5841                                                         weapons.length[weapons.numweapons]=.25;
5842                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
5843                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
5844
5845                                                         weapons.velocity[weapons.numweapons]=0.1;
5846                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
5847                                                         weapons.missed[weapons.numweapons]=1;
5848                                                         weapons.hitsomething[weapons.numweapons]=0;
5849                                                         weapons.freetime[weapons.numweapons]=0;
5850                                                         weapons.firstfree[weapons.numweapons]=1;
5851                                                         weapons.physics[weapons.numweapons]=1;
5852
5853                                                         weapons.owner[0]=1;
5854                                                         weapons.owner[1]=0;
5855                                                         player[0].weaponactive=0;
5856                                                         player[0].num_weapons=1;
5857                                                         player[0].weaponids[0]=1;
5858                                                         player[1].weaponactive=0;
5859                                                         player[1].num_weapons=1;
5860                                                         player[1].weaponids[0]=0;
5861
5862                                                         weapons.numweapons++;
5863                                                 }
5864                                                 if(tutorialstage==48){
5865                                                         canattack=0;
5866                                                         cananger=0;
5867                                                         player[1].aitype=passivetype;
5868
5869                                                         tutorialmaxtime=15;
5870
5871                                                         weapons.owner[0]=1;
5872                                                         weapons.owner[1]=0;
5873                                                         player[0].weaponactive=0;
5874                                                         player[0].num_weapons=1;
5875                                                         player[0].weaponids[0]=1;
5876                                                         player[1].weaponactive=0;
5877                                                         player[1].num_weapons=1;
5878                                                         player[1].weaponids[0]=0;
5879
5880                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
5881                                                         else weapons.type[0]=staff;
5882
5883                                                         weapons.numweapons++;
5884                                                 }
5885                                                 if(tutorialstage==49){
5886                                                         canattack=0;
5887                                                         cananger=0;
5888                                                         player[1].aitype=passivetype;
5889
5890                                                         tutorialmaxtime=200;
5891
5892                                                         weapons.position[1]=1000;
5893                                                         weapons.tippoint[1]=1000;
5894
5895                                                         weapons.numweapons=1;
5896                                                         weapons.owner[0]=0;
5897                                                         player[1].weaponactive=-1;
5898                                                         player[1].num_weapons=0;
5899                                                         player[0].weaponactive=0;
5900                                                         player[0].num_weapons=1;
5901                                                         player[0].weaponids[0]=0;
5902
5903                                                         weapons.type[0]=knife;
5904
5905                                                         weapons.numweapons++;
5906                                                 }
5907                                                 if(tutorialstage==50){
5908                                                         tutorialmaxtime=8;
5909
5910                                                         XYZ temp,temp2;
5911                                                         float gLoc[3];
5912                                                         float vel[3];
5913                                                         gLoc[0]=player[1].coords.x;
5914                                                         gLoc[1]=player[1].coords.y;
5915                                                         gLoc[2]=player[1].coords.z;
5916                                                         vel[0]=0;
5917                                                         vel[1]=0;
5918                                                         vel[2]=0;
5919                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5920                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5921                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5922                                                         OPENAL_SetPaused(channels[fireendsound], false);
5923
5924                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5925                                                                 if(Random()%2==0){
5926                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5927                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5928                                                                         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;
5929                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5930                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5931                                                                 }
5932                                                         }
5933
5934                                                         player[1].num_weapons=0;
5935                                                         player[1].weaponstuck=-1;
5936                                                         player[1].weaponactive=-1;
5937
5938                                                         weapons.numweapons=0;
5939
5940                                                         weapons.owner[0]=-1;
5941                                                         weapons.velocity[0]=0.1;
5942                                                         weapons.tipvelocity[0]=-0.1;
5943                                                         weapons.missed[0]=1;
5944                                                         weapons.hitsomething[0]=0;
5945                                                         weapons.freetime[0]=0;
5946                                                         weapons.firstfree[0]=1;
5947                                                         weapons.physics[0]=1;
5948                                                 }
5949                                                 if(tutorialstage==51){
5950                                                         tutorialmaxtime=80000;
5951                                                 }
5952                                                 if(tutorialstage<=51)tutorialstagetime=0;
5953                                         }
5954
5955                                         //Tutorial success
5956                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
5957                                                 if(tutorialstage==3){
5958                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
5959                                                 }
5960                                                 if(tutorialstage==4){
5961                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
5962                                                 }
5963                                                 if(tutorialstage==5){
5964                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
5965                                                 }
5966                                                 if(tutorialstage==6){
5967                                                         if(player[0].isCrouch())tutorialsuccess=1;
5968                                                 }
5969                                                 if(tutorialstage==7){
5970                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
5971                                                 }
5972                                                 if(tutorialstage==8){
5973                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
5974                                                 }
5975                                                 if(tutorialstage==9){
5976                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
5977                                                 }
5978                                                 if(tutorialstage==11){
5979                                                         if(player[0].isWallJump())tutorialsuccess=1;
5980                                                 }
5981                                                 if(tutorialstage==12){
5982                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
5983                                                 }
5984                                                 if(tutorialstage==15){
5985                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
5986                                                 }
5987                                                 if(tutorialstage==16){
5988                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
5989                                                 }
5990                                                 if(tutorialstage==17){
5991                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
5992                                                 }
5993                                                 if(tutorialstage==18){
5994                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
5995                                                 }
5996                                                 if(tutorialstage==19){
5997                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
5998                                                 }
5999                                                 if(tutorialstage==20){
6000                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6001                                                 }
6002                                                 if(tutorialstage==21){
6003                                                         if(bonus==cannon)tutorialsuccess=1;
6004                                                 }
6005                                                 if(tutorialstage==22){
6006                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6007                                                 }
6008                                                 if(tutorialstage==23){
6009                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6010                                                 }
6011                                                 if(tutorialstage==24){
6012                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6013                                                 }
6014                                                 if(tutorialstage==25){
6015                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6016                                                 }
6017                                                 if(tutorialstage==28){
6018                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6019                                                 }
6020                                                 if(tutorialstage==29){
6021                                                         if(player[0].escapednum==2){
6022                                                                 tutorialsuccess=1;
6023                                                                 reversaltrain=0;
6024                                                                 cananger=0;
6025                                                                 player[1].aitype=passivetype;
6026                                                         }
6027                                                 }
6028                                                 if(tutorialstage==33){
6029                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6030                                                 }
6031                                                 if(tutorialstage==34){
6032                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6033                                                 }
6034                                                 if(tutorialstage==35){
6035                                                         if(animation[player[0].targetanimation].attack==reversal){
6036                                                                 tutorialsuccess=1;
6037                                                                 reversaltrain=0;
6038                                                                 cananger=0;
6039                                                                 player[1].aitype=passivetype;
6040                                                         }
6041                                                 }
6042                                                 if(tutorialstage==40){
6043                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6044                                                 }
6045                                                 if(tutorialstage==41){
6046                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6047                                                 }
6048                                                 if(tutorialstage==43){
6049                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6050                                                 }
6051                                                 if(tutorialstage==44){
6052                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6053                                                 }
6054                                                 if(tutorialstage==45){
6055                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6056                                                 }
6057                                                 if(tutorialstage==46){
6058                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6059                                                 }
6060                                                 if(tutorialstage==49){
6061                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6062                                                 }
6063                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6064
6065
6066                                                 if(tutorialstagetime==tutorialmaxtime-3){
6067                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6068                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6069                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6070                                                 }
6071
6072                                                 if(tutorialsuccess>=1){
6073                                                         if(tutorialstage==34||tutorialstage==35)
6074                                                                 tutorialstagetime=tutorialmaxtime-1;
6075                                                 }
6076                                         }
6077
6078                                         if(tutoriallevel){
6079                                                 if(tutorialstage<14||tutorialstage>=50){
6080                                                         player[1].coords.y=300;
6081                                                         player[1].velocity=0;
6082                                                 }
6083                                         }
6084
6085                                         if(tutoriallevel!=1){
6086                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6087                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6088                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6089                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6090                                                 }
6091                                         }
6092                                         else
6093                                                 if(bonustime==0){
6094                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6095                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6096                                                         OPENAL_SetPaused(channels[fireendsound], false);
6097                                                 }
6098                                                 if(bonustime==0){
6099                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6100                                                         else bonusnum[bonus]+=0.15;
6101                                                         if(tutoriallevel)bonusvalue=0;
6102                                                         bonusvalue/=bonusnum[bonus];
6103                                                         bonustotal+=bonusvalue;
6104                                                 }
6105                                                 bonustime+=multiplier;
6106
6107                                                 if(environment==snowyenvironment){
6108                                                         precipdelay-=multiplier;
6109                                                         while(precipdelay<0){
6110                                                                 precipdelay+=.04;
6111                                                                 if(!detail)precipdelay+=.04;
6112                                                                 XYZ footvel,footpoint;
6113
6114                                                                 footvel=0;
6115                                                                 footpoint=viewer+viewerfacing*6;
6116                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6117                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6118                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6119                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6120                                                         }
6121                                                 }
6122                                                 for(k=0;k<numplayers;k++){
6123                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6124                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6125
6126                                                         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){
6127                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6128                                                                 else if(player[k].rotation>player[k].targetrotation){
6129                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6130                                                                 }
6131                                                                 else if(player[k].rotation<player[k].targetrotation){
6132                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6133                                                                 }
6134                                                         }
6135
6136
6137                                                         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))){
6138                                                                 player[k].turnspeed*=2;
6139                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6140                                                                 else if(player[k].rotation>player[k].targetrotation){
6141                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6142                                                                 }
6143                                                                 else if(player[k].rotation<player[k].targetrotation){
6144                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6145                                                                 }
6146                                                                 player[k].turnspeed/=2;
6147                                                         }
6148
6149                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6150                                                                 player[k].turnspeed*=4;
6151                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6152                                                                 else if(player[k].rotation>player[k].targetrotation){
6153                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6154                                                                 }
6155                                                                 else if(player[k].rotation<player[k].targetrotation){
6156                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6157                                                                 }
6158                                                                 player[k].turnspeed/=4;
6159                                                         }
6160
6161                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6162                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6163
6164                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6165                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6166                                                                         bool tempcollide=0;
6167
6168                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6169                                                                         if(player[k].collide>1)player[k].collide=1;
6170                                                                         player[k].collide-=multiplier*30;
6171
6172                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6173                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6174                                                                         }
6175                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6176                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6177                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6178                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6179                                                                                                 lowpoint=player[k].coords;
6180                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6181                                                                                                 else lowpoint.y+=1.3;
6182                                                                                                 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){
6183                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6184                                                                                                 }
6185                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6186                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6187                                                                                                 */
6188                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6189                                                                                                         flatfacing=lowpoint-player[k].coords;
6190                                                                                                         player[k].coords=lowpoint;
6191                                                                                                         player[k].coords.y-=1.3;
6192                                                                                                         player[k].collide=1;
6193                                                                                                         tempcollide=1;
6194                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6195                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6196                                                                                                                 tempcoords1=lowpoint;
6197                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6198                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6199                                                                                                                         player[k].target=0;
6200                                                                                                                         player[k].targetanimation=walljumpleftanim;
6201                                                                                                                         player[k].targetframe=0;
6202                                                                                                                         float gLoc[3];
6203                                                                                                                         float vel[3];
6204                                                                                                                         gLoc[0]=player[k].coords.x;
6205                                                                                                                         gLoc[1]=player[k].coords.y;
6206                                                                                                                         gLoc[2]=player[k].coords.z;
6207                                                                                                                         vel[0]=0;
6208                                                                                                                         vel[1]=0;
6209                                                                                                                         vel[2]=0;
6210                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6211                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6212                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6213                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6214                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6215
6216                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6217                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6218                                                                                                                         player[k].rotation*=360/6.28;
6219                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6220                                                                                                                         player[k].targetrotation=player[k].rotation;
6221                                                                                                                         player[k].lowrotation=player[k].rotation;
6222                                                                                                                         if(k==0)numwallflipped++;
6223                                                                                                                 }
6224                                                                                                                 else
6225                                                                                                                 {
6226                                                                                                                         lowpoint=tempcoords1;
6227                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6228                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6229                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6230                                                                                                                                 player[k].target=0;
6231                                                                                                                                 player[k].targetanimation=walljumprightanim;
6232                                                                                                                                 player[k].targetframe=0;
6233                                                                                                                                 float gLoc[3];
6234                                                                                                                                 float vel[3];
6235                                                                                                                                 gLoc[0]=player[k].coords.x;
6236                                                                                                                                 gLoc[1]=player[k].coords.y;
6237                                                                                                                                 gLoc[2]=player[k].coords.z;
6238                                                                                                                                 vel[0]=0;
6239                                                                                                                                 vel[1]=0;
6240                                                                                                                                 vel[2]=0;
6241                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6242                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6243                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6244                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6245                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6246
6247                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6248                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6249                                                                                                                                 player[k].rotation*=360/6.28;
6250                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6251                                                                                                                                 player[k].targetrotation=player[k].rotation;
6252                                                                                                                                 player[k].lowrotation=player[k].rotation;
6253                                                                                                                                 if(k==0)numwallflipped++;
6254                                                                                                                         }
6255                                                                                                                         else
6256                                                                                                                         {
6257                                                                                                                                 lowpoint=tempcoords1;
6258                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6259                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6260                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6261                                                                                                                                         player[k].target=0;
6262                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6263                                                                                                                                         player[k].targetframe=0;
6264                                                                                                                                         float gLoc[3];
6265                                                                                                                                         float vel[3];
6266                                                                                                                                         gLoc[0]=player[k].coords.x;
6267                                                                                                                                         gLoc[1]=player[k].coords.y;
6268                                                                                                                                         gLoc[2]=player[k].coords.z;
6269                                                                                                                                         vel[0]=0;
6270                                                                                                                                         vel[1]=0;
6271                                                                                                                                         vel[2]=0;
6272                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6273                                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6274                                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6275                                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6276                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6277
6278                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6279                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6280                                                                                                                                         player[k].rotation*=360/6.28;
6281                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6282                                                                                                                                         player[k].targetrotation=player[k].rotation;
6283                                                                                                                                         player[k].lowrotation=player[k].rotation;
6284                                                                                                                                         if(k==0)numwallflipped++;
6285                                                                                                                                 }
6286                                                                                                                                 else
6287                                                                                                                                 {
6288                                                                                                                                         lowpoint=tempcoords1;
6289                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6290                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6291                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6292                                                                                                                                                 player[k].target=0;
6293                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6294                                                                                                                                                 player[k].targetframe=0;
6295                                                                                                                                                 float gLoc[3];
6296                                                                                                                                                 float vel[3];
6297                                                                                                                                                 gLoc[0]=player[k].coords.x;
6298                                                                                                                                                 gLoc[1]=player[k].coords.y;
6299                                                                                                                                                 gLoc[2]=player[k].coords.z;
6300                                                                                                                                                 vel[0]=0;
6301                                                                                                                                                 vel[1]=0;
6302                                                                                                                                                 vel[2]=0;
6303                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6304                                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6305                                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6306                                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6307                                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6308
6309                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6310                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6311                                                                                                                                                 player[k].rotation*=360/6.28;
6312                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6313                                                                                                                                                 player[k].rotation+=180;
6314                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6315                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6316                                                                                                                                                 if(k==0)numwallflipped++;
6317                                                                                                                                         }
6318                                                                                                                                 }
6319                                                                                                                         }
6320                                                                                                                 }
6321                                                                                                         }
6322                                                                                                 }
6323                                                                                         }
6324                                                                                         else if(objects.type[i]==rocktype){
6325                                                                                                 lowpoint2=player[k].coords;
6326                                                                                                 lowpoint=player[k].coords;
6327                                                                                                 lowpoint.y+=2;
6328                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6329                                                                                                         player[k].coords=colpoint;
6330                                                                                                         player[k].collide=1;
6331                                                                                                         tempcollide=1;
6332
6333                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6334                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6335
6336                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6337                                                                                                                 player[k].target=0;
6338                                                                                                                 player[k].targetframe=0;
6339                                                                                                                 player[k].onterrain=1;
6340
6341                                                                                                                 if(player[k].id==0){
6342                                                                                                                         OPENAL_SetPaused(channels[whooshsound], true);
6343                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
6344                                                                                                                 }
6345
6346                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6347                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6348                                                                                                                         player[k].targetanimation=player[k].getLanding();
6349                                                                                                                         float gLoc[3];
6350                                                                                                                         float vel[3];
6351                                                                                                                         gLoc[0]=player[k].coords.x;
6352                                                                                                                         gLoc[1]=player[k].coords.y;
6353                                                                                                                         gLoc[2]=player[k].coords.z;
6354                                                                                                                         vel[0]=player[k].velocity.x;
6355                                                                                                                         vel[1]=player[k].velocity.y;
6356                                                                                                                         vel[2]=player[k].velocity.z;
6357                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6358                                                                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
6359                                                                                                                         OPENAL_SetVolume(channels[landsound], 128);
6360                                                                                                                         OPENAL_SetPaused(channels[landsound], false);
6361                                                                                                                         if(k==0){
6362                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6363                                                                                                                                 envsoundvol[numenvsounds]=16;
6364                                                                                                                                 envsoundlife[numenvsounds]=.4;
6365                                                                                                                                 numenvsounds++;
6366                                                                                                                         }
6367
6368                                                                                                                 }
6369                                                                                                         }
6370                                                                                                 }
6371                                                                                         }
6372                                                                                 }
6373                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6374                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6375                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6376                                                                                                 lowpoint=player[k].coords;
6377                                                                                                 lowpoint.y+=1.35;
6378                                                                                                 if(objects.type[i]!=rocktype)
6379                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6380                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
6381                                                                                                                 player[k].coords=lowpoint;
6382                                                                                                                 player[k].coords.y-=1.35;
6383                                                                                                                 player[k].collide=1;
6384
6385                                                                                                                 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)){
6386                                                                                                                         lowpoint=player[k].coords;
6387                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6388                                                                                                                         lowpoint=player[k].coords;
6389                                                                                                                         lowpoint.y+=.05;
6390                                                                                                                         facing=0;
6391                                                                                                                         facing.z=-1;
6392                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6393                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6394                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6395                                                                                                                         if(whichhit!=-1){
6396                                                                                                                                 lowpoint=player[k].coords;
6397                                                                                                                                 lowpoint.y+=.1;
6398                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6399                                                                                                                                 lowpoint2=lowpoint;
6400                                                                                                                                 lowpointtarget2=lowpointtarget;
6401                                                                                                                                 lowpoint3=lowpoint;
6402                                                                                                                                 lowpointtarget3=lowpointtarget;
6403                                                                                                                                 lowpoint4=lowpoint;
6404                                                                                                                                 lowpointtarget4=lowpointtarget;
6405                                                                                                                                 lowpoint5=lowpoint;
6406                                                                                                                                 lowpointtarget5=lowpointtarget;
6407                                                                                                                                 lowpoint6=lowpoint;
6408                                                                                                                                 lowpointtarget6=lowpointtarget;
6409                                                                                                                                 lowpoint7=lowpoint;
6410                                                                                                                                 lowpointtarget7=lowpoint;
6411                                                                                                                                 lowpoint2.x+=.1;
6412                                                                                                                                 lowpointtarget2.x+=.1;
6413                                                                                                                                 lowpoint3.z+=.1;
6414                                                                                                                                 lowpointtarget3.z+=.1;
6415                                                                                                                                 lowpoint4.x-=.1;
6416                                                                                                                                 lowpointtarget4.x-=.1;
6417                                                                                                                                 lowpoint5.z-=.1;
6418                                                                                                                                 lowpointtarget5.z-=.1;
6419                                                                                                                                 lowpoint6.y+=45/13;
6420                                                                                                                                 lowpointtarget6.y+=45/13;
6421                                                                                                                                 lowpointtarget6+=facing*.6;
6422                                                                                                                                 lowpointtarget7.y+=90/13;
6423                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6424                                                                                                                                 if(objects.friction[i]>.5)
6425                                                                                                                                         if(whichhit!=-1){
6426                                                                                                                                                 //if(k==0){
6427                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6428                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6429                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6430                                                                                                                                                                 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)
6431                                                                                                                                                                         for(j=0;j<45;j++){
6432                                                                                                                                                                                 lowpoint=player[k].coords;
6433                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6434                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6435                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6436                                                                                                                                                                                         if(j<=6){
6437                                                                                                                                                                                                 j=100;
6438                                                                                                                                                                                         }
6439                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6440                                                                                                                                                                                         j=100;
6441                                                                                                                                                                                         }*/
6442                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6443                                                                                                                                                                                                 j=100;
6444                                                                                                                                                                                         }
6445                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6446                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6447                                                                                                                                                                                                 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)*/){
6448                                                                                                                                                                                                         lowpoint=player[k].coords;
6449                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6450                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6451                                                                                                                                                                                                         flatfacing=player[k].coords;
6452                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6453                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6454                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6455
6456                                                                                                                                                                                                         if(j>10||!player[k].isRun()){
6457                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6458                                                                                                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6459                                                                                                                                                                                                                 }
6460                                                                                                                                                                                                                 float gLoc[3];
6461                                                                                                                                                                                                                 float vel[3];
6462                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6463                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6464                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6465                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6466                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6467                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6468                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
6469                                                                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6470                                                                                                                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
6471                                                                                                                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
6472
6473                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6474                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6475                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6476                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6477                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6478                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6479
6480                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6481                                                                                                                                                                                                                 player[k].velocity=0;
6482
6483                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6484                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6485                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6486                                                                                                                                                                                                                         player[k].jumppower=0;
6487                                                                                                                                                                                                                         player[k].jumpclimb=1;
6488                                                                                                                                                                                                                 }
6489                                                                                                                                                                                                                 player[k].transspeed=6;
6490                                                                                                                                                                                                                 player[k].target=0;
6491
6492                                                                                                                                                                                                                 //player[k].currentframe=1;
6493                                                                                                                                                                                                                 player[k].targetframe=1;
6494                                                                                                                                                                                                                 if(j>25){
6495                                                                                                                                                                                                                         //player[k].currentframe=0;
6496                                                                                                                                                                                                                         player[k].targetframe=0;
6497                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6498                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6499                                                                                                                                                                                                                         player[k].jumppower=0;
6500                                                                                                                                                                                                                 }
6501                                                                                                                                                                                                         }
6502                                                                                                                                                                                                         j=100;
6503                                                                                                                                                                                                 }
6504                                                                                                                                                                                         }
6505                                                                                                                                                                                 }
6506                                                                                                                                                                         }
6507                                                                                                                                                                         //}
6508                                                                                                                                         }
6509                                                                                                                         }
6510                                                                                                                 }
6511                                                                                                         }
6512                                                                                         }
6513                                                                                         if(player[k].collide<=0){
6514                                                                                                 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()){
6515                                                                                                         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)){
6516                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6517                                                                                                                 player[k].targetanimation=jumpdownanim;
6518                                                                                                                 player[k].targetframe=0;
6519                                                                                                                 player[k].target=0;
6520
6521                                                                                                                 float gLoc[3];
6522                                                                                                                 float vel[3];
6523                                                                                                                 gLoc[0]=player[k].coords.x;
6524                                                                                                                 gLoc[1]=player[k].coords.y;
6525                                                                                                                 gLoc[2]=player[k].coords.z;
6526                                                                                                                 vel[0]=player[k].velocity.x;
6527                                                                                                                 vel[1]=player[k].velocity.y;
6528                                                                                                                 vel[2]=player[k].velocity.z;
6529                                                                                                                 if(k==0){
6530                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
6531                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6532                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
6533                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
6534                                                                                                                 }
6535                                                                                                         }
6536                                                                                                         player[k].velocity.y+=gravity;
6537                                                                                                 }
6538                                                                                         }
6539                                                                 }
6540                                                         }
6541                                                         player[k].realoldcoords=player[k].coords;
6542                                                 }
6543
6544                                                 static XYZ oldviewer;
6545
6546                                                 if(indialogue==-1){
6547                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6548                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6549                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6550                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6551                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6552                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6553                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6554                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6555                                                 }
6556                                                 else
6557                                                 {
6558                                                         player[0].forwardkeydown=0;
6559                                                         player[0].leftkeydown=0;
6560                                                         player[0].backkeydown=0;
6561                                                         player[0].rightkeydown=0;
6562                                                         player[0].jumpkeydown=0;
6563                                                         player[0].crouchkeydown=0;
6564                                                         player[0].drawkeydown=0;
6565                                                         player[0].throwkeydown=0;
6566                                                 }
6567
6568                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6569
6570
6571                                                 static bool endkeydown;
6572                                                 if(indialogue!=-1){
6573                                                         cameramode=1;
6574                                                         if(directing){
6575                                                                 facing=0;
6576                                                                 facing.z=-1;
6577
6578                                                                 facing=DoRotation(facing,-rotation2,0,0);
6579                                                                 facing=DoRotation(facing,0,0-rotation,0);
6580
6581                                                                 flatfacing=0;
6582                                                                 flatfacing.z=-1;
6583
6584                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6585
6586                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6587                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6588                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6589                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6590                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6591                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6592                                                                 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)
6593                                                                         ||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)
6594                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6595                                                                                 int whichend;
6596                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6597                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6598                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6599                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6600                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6601                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6602                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6603                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6604                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6605                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6606                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6607                                                                                 if(whichend!=-1){
6608                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6609                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6610                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6611                                                                                 }
6612                                                                                 if(whichend==-1){
6613                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6614                                                                                 }
6615                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6616                                                                                         indialogue=-1;
6617                                                                                         directing=0;
6618                                                                                         cameramode=0;
6619                                                                                 }
6620                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6621                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6622                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6623                                                                                 indialogue++;
6624                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6625                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6626                                                                                                 static float gLoc[3];
6627                                                                                                 static float vel[3];
6628                                                                                                 XYZ temppos;
6629                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6630                                                                                                 temppos=temppos-viewer;
6631                                                                                                 Normalise(&temppos);
6632                                                                                                 temppos+=viewer;
6633
6634                                                                                                 gLoc[0]=temppos.x;
6635                                                                                                 gLoc[1]=temppos.y;
6636                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
6637                                                                                                 vel[1]=0;
6638                                                                                                 vel[2]=0;
6639                                                                                                 int whichsoundplay;
6640                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6641                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6642                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6643                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6644                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6645                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6646                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6647                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6648                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6649                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6650                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6651                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6652                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6653                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6654                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6655                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6656                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6657                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6658                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6659                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6660                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6661                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6662                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6663                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6664                                                                                         }
6665                                                                                 }
6666
6667                                                                                 for(j=0;j<numplayers;j++){
6668                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6669                                                                                 }
6670
6671                                                                                 endkeydown=1;
6672                                                                         }
6673                                                                         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)
6674                                                                                 ||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)
6675                                                                                 )){
6676                                                                                         int whichend;
6677                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
6678                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
6679                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
6680                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
6681                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
6682                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
6683                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
6684                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
6685                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
6686                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
6687                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
6688                                                                                 }
6689                                                                                 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)
6690                                                                                         &&!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)
6691                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6692                                                                                                 endkeydown=0;
6693                                                                                         }
6694                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6695                                                                                                 indialogue=-1;
6696                                                                                                 directing=0;
6697                                                                                                 cameramode=0;
6698                                                                                         }
6699                                                         }
6700                                                         if(!directing){
6701                                                                 OPENAL_SetPaused(channels[whooshsound], true);
6702                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
6703                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
6704                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
6705                                                                 }
6706                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6707                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6708                                                                 if(dialoguetime>0.5)
6709                                                                         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)
6710                                                                                 ||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)
6711                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
6712                                                                                         indialogue++;
6713                                                                                         endkeydown=1;
6714                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
6715                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6716                                                                                                         static float gLoc[3];
6717                                                                                                         static float vel[3];
6718                                                                                                         XYZ temppos;
6719                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6720                                                                                                         temppos=temppos-viewer;
6721                                                                                                         Normalise(&temppos);
6722                                                                                                         temppos+=viewer;
6723
6724                                                                                                         gLoc[0]=temppos.x;
6725                                                                                                         gLoc[1]=temppos.y;
6726                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
6727                                                                                                         vel[1]=0;
6728                                                                                                         vel[2]=0;
6729                                                                                                         int whichsoundplay;
6730                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6731                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6732                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6733                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6734                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6735                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6736                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6737                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6738                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6739                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6740                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6741                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6742                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6743                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6744                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6745                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6746                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6747                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6748                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6749                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6750                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
6751                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
6752                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6753                                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6754                                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6755                                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6756                                                                                                         }
6757                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
6758                                                                                                                 hotspot[numhotspots]=player[0].coords;
6759                                                                                                                 hotspotsize[numhotspots]=10;
6760                                                                                                                 hotspottype[numhotspots]=-1;
6761
6762                                                                                                                 numhotspots++;
6763                                                                                                         }
6764                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
6765                                                                                                                 hostile=1;
6766                                                                                                         }
6767
6768                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
6769                                                                                                                 indialogue=-1;
6770                                                                                                                 directing=0;
6771                                                                                                                 cameramode=0;
6772                                                                                                         }
6773                                                                                                 }
6774                                                                                         }
6775                                                                                 }
6776                                                                                 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)
6777                                                                                         &&!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)
6778                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6779                                                                                                 endkeydown=0;
6780                                                                                         }
6781                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6782                                                                                                 indialogue=-1;
6783                                                                                                 directing=0;
6784                                                                                                 cameramode=0;
6785                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6786                                                                                                         hostile=1;
6787                                                                                                 }
6788                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6789                                                                                                         windialogue=1;
6790                                                                                                 }
6791                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6792                                                                                                         hostile=1;
6793                                                                                                         for(i=1;i<numplayers;i++){
6794                                                                                                                 player[i].aitype = attacktypecutoff;
6795                                                                                                         }
6796                                                                                                 }
6797                                                                                         }
6798                                                         }
6799                                                 }
6800
6801                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
6802                                                 else oldbuttondialogue=1;
6803
6804                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
6805
6806                                                 //Net updates
6807
6808                                                 /*keyrefreshdelay-=multiplier;
6809                                                 bigrefreshdelay-=multiplier;
6810
6811                                                 if(keyrefreshdelay<=0){
6812                                                 static int concat[4];
6813
6814                                                 concat[0]=player[0].forwardkeydown;
6815                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
6816                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
6817                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
6818                                                 concat[0]=concat[0]*2+player[0].backkeydown;
6819                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
6820                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
6821                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
6822
6823                                                 concat[1]=player[0].crouchtogglekeydown;
6824                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
6825                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
6826                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
6827                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
6828                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
6829
6830                                                 //concat[2]=(char)((int)(rotation/2)%180);
6831
6832                                                 //concat[3]=(char)((int)(rotation2/2)%180);
6833
6834                                                 chatname[0]=concat[0]-128;
6835                                                 chatname[1]=concat[1]-128;
6836                                                 //chatname[2]=concat[2]-128;
6837                                                 //chatname[3]=concat[3]-128;
6838                                                 int temppoint=2;
6839                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
6840                                                 temppoint+=sizeof(float);
6841                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
6842                                                 temppoint+=sizeof(float);
6843
6844                                                 chatname[temppoint]='\0';
6845
6846                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
6847                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
6848                                                 //keyrefreshdelay=.01;
6849                                                 keyrefreshdelay=.03;
6850                                                 }
6851
6852                                                 if(bigrefreshdelay<=0){
6853                                                 for(i=0;i<1;i++){
6854                                                 /*int temppoint=0;
6855                                                 memcpy(chatname+temppoint,&i,sizeof(int));
6856                                                 temppoint+=sizeof(int);
6857                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
6858                                                 temppoint+=sizeof(float);
6859                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
6860                                                 temppoint+=sizeof(float);
6861                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
6862                                                 temppoint+=sizeof(float);
6863                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
6864                                                 temppoint+=sizeof(float);
6865                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
6866                                                 temppoint+=sizeof(float);
6867                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
6868                                                 temppoint+=sizeof(int);
6869                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
6870                                                 temppoint+=sizeof(int);
6871                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
6872                                                 temppoint+=sizeof(float);
6873                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
6874                                                 temppoint+=sizeof(float);
6875                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
6876                                                 temppoint+=sizeof(float);
6877                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
6878                                                 temppoint+=sizeof(int);
6879                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
6880                                                 temppoint+=sizeof(int);
6881                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
6882                                                 temppoint+=sizeof(float);
6883                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
6884                                                 temppoint+=sizeof(float);
6885                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
6886                                                 temppoint+=sizeof(float);
6887                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
6888                                                 temppoint+=sizeof(int);
6889                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
6890                                                 temppoint+=sizeof(int);
6891                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
6892                                                 temppoint+=sizeof(int);
6893                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
6894                                                 temppoint+=sizeof(int);
6895                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
6896                                                 temppoint+=sizeof(int);
6897                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
6898                                                 temppoint+=sizeof(int);
6899                                                 chatname[temppoint]='\0';
6900
6901                                                 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);
6902                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
6903                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
6904
6905                                                 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);
6906
6907                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
6908                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
6909                                                 }
6910                                                 //bigrefreshdelay=.02;
6911                                                 bigrefreshdelay=.1;
6912                                                 }
6913                                                 }*/
6914
6915                                                 if(!player[0].jumpkeydown){
6916                                                         player[0].jumptogglekeydown=0;
6917                                                 }
6918                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
6919
6920
6921                                                 dialoguetime+=multiplier;
6922                                                 skybox.cloudmove+=multiplier;
6923                                                 hawkrotation+=multiplier*25;
6924                                                 realhawkcoords=0;
6925                                                 realhawkcoords.x=25;
6926                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6927                                                 hawkcalldelay-=multiplier/2;
6928
6929                                                 if(hawkcalldelay<=0)
6930                                                 {
6931                                                         static float gLoc[3];
6932                                                         static float vel[3];
6933                                                         gLoc[0]=realhawkcoords.x;
6934                                                         gLoc[1]=realhawkcoords.y;
6935                                                         gLoc[2]=realhawkcoords.z;
6936                                                         vel[0]=0;
6937                                                         vel[1]=0;
6938                                                         vel[2]=0;
6939                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, true);
6940                                                         OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
6941                                                         OPENAL_SetVolume(channels[hawksound], 128);
6942                                                         OPENAL_SetPaused(channels[hawksound], false);
6943
6944                                                         hawkcalldelay=16+abs(Random()%8);
6945                                                 }
6946                                                 static float temptexdetail;
6947
6948
6949                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
6950                                                         player[0].damagetolerance=200000;
6951                                                         player[0].damage=0;
6952                                                         player[0].burnt=0;
6953                                                         player[0].permanentdamage=0;
6954                                                         player[0].superpermanentdamage=0;
6955                                                         /*
6956                                                         int whichchar;
6957                                                         whichchar = abs(Random()%7);
6958                                                         registrationname[whichchar]+=1;
6959                                                         */
6960                                                 }
6961
6962                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
6963                                                         environment++;
6964                                                         if(environment>2)environment=0;
6965                                                         Setenvironment(environment);
6966
6967                                                         envtogglekeydown=1;
6968                                                 }
6969
6970
6971                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
6972                                                         envtogglekeydown=0;
6973                                                 }
6974
6975                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
6976                                                         cameramode=1-cameramode;
6977                                                         cameratogglekeydown=1;
6978                                                 }
6979
6980                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
6981                                                         cameratogglekeydown=0;
6982                                                 }
6983
6984                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
6985                                                         if(player[0].num_weapons>0){
6986                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
6987                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
6988                                                                 else weapons.type[player[0].weaponids[0]]=sword;
6989                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
6990                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
6991                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
6992                                                                         weapons.length[player[0].weaponids[0]]=.8;
6993                                                                 }
6994                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
6995                                                                         weapons.mass[player[0].weaponids[0]]=2;
6996                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
6997                                                                         weapons.length[player[0].weaponids[0]]=1.5;
6998                                                                 }
6999
7000                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7001                                                                         weapons.mass[player[0].weaponids[0]]=1;
7002                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7003                                                                         weapons.length[player[0].weaponids[0]]=.25;
7004                                                                 }
7005                                                         }
7006
7007                                                         /*for(i=0;i<objects.numobjects;i++){
7008                                                         if(objects.type[i]==treeleavestype){
7009                                                         for(j=0;j<objects.numobjects;j++){
7010                                                         if(objects.type[j]==treetrunktype)
7011                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7012                                                         objects.scale[i]=objects.scale[j];
7013                                                         }
7014                                                         }
7015                                                         }*/
7016                                                         detailtogglekeydown=1;
7017                                                 }
7018
7019                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7020                                                         int closest=-1;
7021                                                         float closestdist=-1;
7022                                                         float distance;
7023                                                         if(numplayers>1)
7024                                                                 for(i=1;i<numplayers;i++){
7025                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7026                                                                         if(closestdist==-1||distance<closestdist){
7027                                                                                 closestdist=distance;
7028                                                                                 closest=i;
7029                                                                         }
7030                                                                 }
7031                                                                 if(closest!=-1){
7032                                                                         if(player[closest].num_weapons)
7033                                                                         {
7034                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7035                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7036                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7037                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7038                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7039                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7040                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7041                                                                                 }
7042                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7043                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7044                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7045                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7046                                                                                 }
7047                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7048                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7049                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7050                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7051                                                                                 }
7052                                                                         }
7053                                                                         if(!player[closest].num_weapons)
7054                                                                         {
7055                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7056                                                                                 weapons.owner[weapons.numweapons]=closest;
7057                                                                                 weapons.type[weapons.numweapons]=knife;
7058                                                                                 weapons.damage[weapons.numweapons]=0;
7059                                                                                 weapons.numweapons++;
7060                                                                                 player[closest].num_weapons=1;
7061                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7062                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7063                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7064                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7065                                                                                 }
7066                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7067                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7068                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7069                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7070                                                                                 }
7071                                                                         }
7072                                                                 }
7073                                                                 detailtogglekeydown=1;
7074                                                 }
7075
7076                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7077                                                         int closest=-1;
7078                                                         float closestdist=-1;
7079                                                         float distance;
7080                                                         if(numplayers>1)
7081                                                                 for(i=1;i<numplayers;i++){
7082                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7083                                                                         if(closestdist==-1||distance<closestdist){
7084                                                                                 closestdist=distance;
7085                                                                                 closest=i;
7086                                                                         }
7087                                                                 }
7088
7089                                                                 player[closest].rotation+=multiplier*50;
7090                                                                 player[closest].targetrotation=player[closest].rotation;
7091                                                 }
7092
7093
7094                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7095                                                         int closest=-1;
7096                                                         float closestdist=-1;
7097                                                         float distance;
7098                                                         if(numplayers>1)
7099                                                                 for(i=1;i<numplayers;i++){
7100                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7101                                                                         if(closestdist==-1||distance<closestdist){
7102                                                                                 closestdist=distance;
7103                                                                                 closest=i;
7104                                                                         }
7105                                                                 }
7106                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7107
7108                                                                 if(closest!=-1){
7109                                                                         player[closest].whichskin++;
7110                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7111                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7112
7113                                                                         LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
7114                                                                                         &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7115                                                                 }
7116
7117                                                                 if(player[closest].numclothes){
7118                                                                         for(i=0;i<player[closest].numclothes;i++){
7119                                                                                 tintr=player[closest].clothestintr[i];
7120                                                                                 tintg=player[closest].clothestintg[i];
7121                                                                                 tintb=player[closest].clothestintb[i];
7122                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7123                                                                         }
7124                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7125                                                                 }
7126
7127                                                                 detailtogglekeydown=1;
7128                                                 }
7129
7130                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7131                                                         int closest=-1;
7132                                                         float closestdist=-1;
7133                                                         float distance;
7134                                                         if(numplayers>1)
7135                                                                 for(i=1;i<numplayers;i++){
7136                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7137                                                                         if(closestdist==-1||distance<closestdist){
7138                                                                                 closestdist=distance;
7139                                                                                 closest=i;
7140                                                                         }
7141                                                                 }
7142                                                                 if(closest!=-1){
7143                                                                         if(player[closest].creature==wolftype){
7144                                                                                 headprop=player[closest].proportionhead.x/1.1;
7145                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7146                                                                                 armprop=player[closest].proportionarms.x/1.1;
7147                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7148                                                                         }
7149
7150                                                                         if(player[closest].creature==rabbittype){
7151                                                                                 headprop=player[closest].proportionhead.x/1.2;
7152                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7153                                                                                 armprop=player[closest].proportionarms.x/1.00;
7154                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7155                                                                         }
7156
7157
7158                                                                         if(player[closest].creature==rabbittype){
7159                                                                                 player[closest].skeleton.id=closest;
7160                                                                                 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);
7161                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7162                                                                                 player[closest].whichskin=0;
7163                                                                                 player[closest].creature=wolftype;
7164
7165                                                                                 player[closest].proportionhead=1.1;
7166                                                                                 player[closest].proportionbody=1.1;
7167                                                                                 player[closest].proportionarms=1.1;
7168                                                                                 player[closest].proportionlegs=1.1;
7169                                                                                 player[closest].proportionlegs.y=1.1;
7170                                                                                 player[closest].scale=.23*5*player[0].scale;
7171
7172                                                                                 player[closest].damagetolerance=300;
7173                                                                         }
7174                                                                         else
7175                                                                         {
7176                                                                                 player[closest].skeleton.id=closest;
7177                                                                                 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);
7178                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7179                                                                                 player[closest].whichskin=0;
7180                                                                                 player[closest].creature=rabbittype;
7181
7182                                                                                 player[closest].proportionhead=1.2;
7183                                                                                 player[closest].proportionbody=1.05;
7184                                                                                 player[closest].proportionarms=1.00;
7185                                                                                 player[closest].proportionlegs=1.1;
7186                                                                                 player[closest].proportionlegs.y=1.05;
7187                                                                                 player[closest].scale=.2*5*player[0].scale;
7188
7189                                                                                 player[closest].damagetolerance=200;
7190                                                                         }
7191
7192                                                                         if(player[closest].creature==wolftype){
7193                                                                                 player[closest].proportionhead=1.1*headprop;
7194                                                                                 player[closest].proportionbody=1.1*bodyprop;
7195                                                                                 player[closest].proportionarms=1.1*armprop;
7196                                                                                 player[closest].proportionlegs=1.1*legprop;
7197                                                                         }
7198
7199                                                                         if(player[closest].creature==rabbittype){
7200                                                                                 player[closest].proportionhead=1.2*headprop;
7201                                                                                 player[closest].proportionbody=1.05*bodyprop;
7202                                                                                 player[closest].proportionarms=1.00*armprop;
7203                                                                                 player[closest].proportionlegs=1.1*legprop;
7204                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7205                                                                         }
7206
7207                                                                 }
7208                                                                 detailtogglekeydown=1;
7209                                                 }
7210
7211                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7212                                                         detailtogglekeydown=0;
7213                                                 }
7214
7215                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7216                                                         slomo=1-slomo;
7217                                                         slomodelay=1000;
7218                                                         slomotogglekeydown=1;
7219                                                 }
7220
7221
7222                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7223                                                         int closest=-1;
7224                                                         float closestdist=-1;
7225                                                         float distance;
7226                                                         XYZ flatfacing2,flatvelocity2;
7227                                                         XYZ blah;
7228                                                         if(numplayers>1)
7229                                                                 for(i=1;i<numplayers;i++){
7230                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7231                                                                         if(distance<144&&!player[i].headless)
7232                                                                                 if(closestdist==-1||distance<closestdist){
7233                                                                                         closestdist=distance;
7234                                                                                         closest=i;
7235                                                                                         blah = player[i].coords;
7236                                                                                 }
7237                                                                 }
7238
7239                                                                 if(closest!=-1){
7240                                                                         XYZ headspurtdirection;
7241                                                                         int i = player[closest].skeleton.jointlabels[head];
7242                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7243                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7244                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7245                                                                                 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;
7246                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7247                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7248                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7249                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7250                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7251                                                                                 Normalise(&headspurtdirection);
7252                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7253                                                                                 flatvelocity2+=headspurtdirection*8;
7254                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7255                                                                         }
7256                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7257
7258                                                                         float gLoc[3];
7259                                                                         float vel[3];
7260                                                                         gLoc[0]=blah.x;
7261                                                                         gLoc[1]=blah.y;
7262                                                                         gLoc[2]=blah.z;
7263                                                                         vel[0]=0;
7264                                                                         vel[1]=0;
7265                                                                         vel[2]=0;
7266                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7267                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7268                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7269                                                                         OPENAL_SetPaused(channels[splattersound], false);
7270
7271                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7272                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7273                                                                         OPENAL_SetVolume(channels[breaksound2], 100);
7274                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7275
7276                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7277                                                                         player[closest].RagDoll(0);
7278                                                                         player[closest].dead=2;
7279                                                                         player[closest].headless=1;
7280                                                                         player[closest].DoBloodBig(3,165);
7281
7282                                                                         camerashake+=.3;
7283                                                                 }
7284
7285                                                                 explodetogglekeydown=1;
7286                                                 }
7287
7288                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7289                                                         int closest=-1;
7290                                                         float closestdist=-1;
7291                                                         float distance;
7292                                                         XYZ flatfacing2,flatvelocity2;
7293                                                         XYZ blah;
7294                                                         if(numplayers>1)
7295                                                                 for(i=1;i<numplayers;i++){
7296                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7297                                                                         if(distance<144)
7298                                                                                 if(closestdist==-1||distance<closestdist){
7299                                                                                         closestdist=distance;
7300                                                                                         closest=i;
7301                                                                                         blah=player[i].coords;
7302                                                                                 }
7303                                                                 }
7304
7305                                                                 if(closest!=-1){
7306                                                                         float gLoc[3];
7307                                                                         float vel[3];
7308                                                                         gLoc[0]=blah.x;
7309                                                                         gLoc[1]=blah.y;
7310                                                                         gLoc[2]=blah.z;
7311                                                                         vel[0]=0;
7312                                                                         vel[1]=0;
7313                                                                         vel[2]=0;
7314
7315                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7316                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7317                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7318                                                                         OPENAL_SetPaused(channels[splattersound], false);
7319
7320                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7321                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7322                                                                         OPENAL_SetVolume(channels[breaksound2], 600);
7323                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7324
7325                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7326                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7327                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7328                                                                                 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;
7329                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7330                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7331                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7332                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7333                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7334                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7335                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7336                                                                         }
7337
7338                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7339                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7340                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7341                                                                                 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;
7342                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7343                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7344                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7345                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7346                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7347                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7348                                                                         }
7349
7350                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7351                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7352                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7353                                                                                 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;
7354                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7355                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7356                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7357                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7358                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7359                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7360                                                                         }
7361
7362                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7363                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7364                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7365                                                                                 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;
7366                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7367                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7368                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7369                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7370                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7371                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7372                                                                         }
7373
7374                                                                         XYZ temppos;
7375                                                                         for(j=0;j<numplayers; j++){
7376                                                                                 if(j!=closest){
7377                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7378                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7379                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7380                                                                                                 player[j].skeleton.longdead=0;
7381                                                                                                 player[j].RagDoll(0);
7382                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7383                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7384                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7385                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7386                                                                                                                 Normalise(&flatvelocity2);
7387                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7388                                                                                                         }
7389                                                                                                 }
7390                                                                                         }
7391                                                                                 }
7392                                                                         }
7393
7394                                                                         player[closest].DoDamage(10000);
7395                                                                         player[closest].RagDoll(0);
7396                                                                         player[closest].dead=2;
7397                                                                         player[closest].coords=20;
7398                                                                         player[closest].skeleton.free=2;
7399
7400                                                                         camerashake+=.6;
7401
7402                                                                 }
7403
7404                                                                 explodetogglekeydown=1;
7405                                                 }
7406
7407                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7408                                                         explodetogglekeydown=0;
7409                                                 }
7410
7411                                                 /*
7412                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7413                                                 FILE                    *tfile;
7414                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7415                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7416                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7417                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7418                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7419                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7420                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7421
7422                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7423                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7424                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7425                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7426                                                 for(j=0;j<player[0].num_weapons;j++){
7427                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7428                                                 }
7429                                                 fwrite( &environment, 1, sizeof(int), tfile );
7430
7431                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7432                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7433                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7434                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7435                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7436
7437                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7438                                                 if(numplayers>1&&numplayers<maxplayers)
7439                                                 for(i=1;i<numplayers;i++){
7440                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7441                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7442                                                 for(j=0;j<player[i].num_weapons;j++){
7443                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7444                                                 }
7445                                                 if(player[i].numwaypoints<30){
7446                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7447                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7448                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7449                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7450                                                 }
7451                                                 else{
7452                                                 player[i].numwaypoints=0;
7453                                                 player[i].waypoint=0;
7454                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7455                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7456                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7457                                                 }
7458                                                 }
7459
7460                                                 fclose(tfile);
7461
7462                                                 slomotogglekeydown=1;
7463                                                 }*/
7464
7465                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7466                                                         slomotogglekeydown=0;
7467                                                 }
7468
7469
7470                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7471                                                         player[0].onfire=1-player[0].onfire;
7472                                                         if(player[0].onfire){
7473                                                                 player[0].CatchFire();
7474                                                         }
7475                                                         if(!player[0].onfire){
7476                                                                 float gLoc[3];
7477                                                                 float vel[3];
7478                                                                 gLoc[0]=player[0].coords.x;
7479                                                                 gLoc[1]=player[0].coords.y;
7480                                                                 gLoc[2]=player[0].coords.z;
7481                                                                 vel[0]=0;
7482                                                                 vel[1]=0;
7483                                                                 vel[2]=0;
7484                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7485                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7486                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
7487                                                                 OPENAL_SetPaused(channels[fireendsound], false);
7488                                                                 OPENAL_SetPaused(channels[stream_firesound], true);
7489                                                         }
7490                                                         slomotogglekeydown=1;
7491                                                 }
7492                                                 /*
7493                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7494                                                 if(player[0].bleeding<=0)
7495                                                 player[0].DoBlood(1,255);
7496                                                 }*/
7497
7498
7499                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7500                                                         int closest=-1;
7501                                                         float closestdist=-1;
7502                                                         float distance;
7503                                                         if(numplayers>1)
7504                                                                 for(i=1;i<numplayers;i++){
7505                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7506                                                                         if(closestdist==-1||distance<closestdist){
7507                                                                                 closestdist=distance;
7508                                                                                 closest=i;
7509                                                                         }
7510                                                                 }
7511                                                                 if(closestdist>0&&closest>=0){
7512                                                                         //player[closest]=player[numplayers-1];
7513                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7514                                                                         numplayers--;
7515                                                                 }
7516                                                                 drawmodetogglekeydown=1;
7517                                                 }
7518
7519                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7520                                                         int closest=-1;
7521                                                         float closestdist=-1;
7522                                                         float distance;
7523                                                         if(max_objects>1)
7524                                                                 for(i=1;i<max_objects;i++){
7525                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7526                                                                         if(closestdist==-1||distance<closestdist){
7527                                                                                 closestdist=distance;
7528                                                                                 closest=i;
7529                                                                         }
7530                                                                 }
7531                                                                 if(closestdist>0&&closest>=0){
7532                                                                         objects.position[closest].y-=500;
7533                                                                 }
7534                                                                 drawmodetogglekeydown=1;
7535                                                 }
7536
7537                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7538                                                         //drawmode++;
7539                                                         //if(drawmode>2)drawmode=0;
7540                                                         if(objects.numobjects<max_objects-1){
7541                                                                 XYZ boxcoords;
7542                                                                 boxcoords.x=player[0].coords.x;
7543                                                                 boxcoords.z=player[0].coords.z;
7544                                                                 boxcoords.y=player[0].coords.y-3;
7545                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7546                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7547                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7548                                                                 float temprotat,temprotat2;
7549                                                                 temprotat=editorrotation;
7550                                                                 temprotat2=editorrotation2;
7551                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7552                                                                 if(temprotat2<0)temprotat2=Random()%360;
7553
7554                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7555                                                                 if(editortype==treetrunktype)
7556                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7557                                                         }
7558
7559                                                         drawmodetogglekeydown=1;
7560                                                 }
7561
7562                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7563                                                         if(numplayers<maxplayers-1){
7564                                                                 player[numplayers].scale=.2*5*player[0].scale;
7565                                                                 player[numplayers].creature=rabbittype;
7566                                                                 player[numplayers].howactive=editoractive;
7567                                                                 player[numplayers].skeleton.id=numplayers;
7568                                                                 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);
7569
7570                                                                 //texsize=512*512*3/texdetail/texdetail;
7571                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7572                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7573
7574                                                                 k=abs(Random()%2)+1;
7575                                                                 if(k==0){
7576                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7577                                                                         player[numplayers].whichskin=0;
7578                                                                 }
7579                                                                 else if(k==1){
7580                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7581                                                                         player[numplayers].whichskin=1;
7582                                                                 }
7583                                                                 else {
7584                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7585                                                                         player[numplayers].whichskin=2;
7586                                                                 }
7587
7588                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7589                                                                 player[numplayers].power=1;
7590                                                                 player[numplayers].speedmult=1;
7591                                                                 player[numplayers].currentanimation=bounceidleanim;
7592                                                                 player[numplayers].targetanimation=bounceidleanim;
7593                                                                 player[numplayers].currentframe=0;
7594                                                                 player[numplayers].targetframe=1;
7595                                                                 player[numplayers].target=0;
7596                                                                 player[numplayers].bled=0;
7597                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
7598
7599                                                                 player[numplayers].targetrotation=player[0].targetrotation;
7600                                                                 player[numplayers].rotation=player[0].rotation;
7601
7602                                                                 player[numplayers].velocity=0;
7603                                                                 player[numplayers].coords=player[0].coords;
7604                                                                 player[numplayers].oldcoords=player[numplayers].coords;
7605                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
7606
7607                                                                 player[numplayers].id=numplayers;
7608                                                                 player[numplayers].skeleton.id=numplayers;
7609                                                                 player[numplayers].updatedelay=0;
7610                                                                 player[numplayers].normalsupdatedelay=0;
7611
7612                                                                 player[numplayers].aitype=passivetype;
7613                                                                 player[numplayers].aitarget=0;
7614
7615                                                                 if(player[0].creature==wolftype){
7616                                                                         headprop=player[0].proportionhead.x/1.1;
7617                                                                         bodyprop=player[0].proportionbody.x/1.1;
7618                                                                         armprop=player[0].proportionarms.x/1.1;
7619                                                                         legprop=player[0].proportionlegs.x/1.1;
7620                                                                 }
7621
7622                                                                 if(player[0].creature==rabbittype){
7623                                                                         headprop=player[0].proportionhead.x/1.2;
7624                                                                         bodyprop=player[0].proportionbody.x/1.05;
7625                                                                         armprop=player[0].proportionarms.x/1.00;
7626                                                                         legprop=player[0].proportionlegs.x/1.1;
7627                                                                 }
7628
7629                                                                 if(player[numplayers].creature==wolftype){
7630                                                                         player[numplayers].proportionhead=1.1*headprop;
7631                                                                         player[numplayers].proportionbody=1.1*bodyprop;
7632                                                                         player[numplayers].proportionarms=1.1*armprop;
7633                                                                         player[numplayers].proportionlegs=1.1*legprop;
7634                                                                 }
7635
7636                                                                 if(player[numplayers].creature==rabbittype){
7637                                                                         player[numplayers].proportionhead=1.2*headprop;
7638                                                                         player[numplayers].proportionbody=1.05*bodyprop;
7639                                                                         player[numplayers].proportionarms=1.00*armprop;
7640                                                                         player[numplayers].proportionlegs=1.1*legprop;
7641                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
7642                                                                 }
7643
7644                                                                 player[numplayers].headless=0;
7645                                                                 player[numplayers].onfire=0;
7646
7647                                                                 if(cellophane){
7648                                                                         player[numplayers].proportionhead.z=0;
7649                                                                         player[numplayers].proportionbody.z=0;
7650                                                                         player[numplayers].proportionarms.z=0;
7651                                                                         player[numplayers].proportionlegs.z=0;
7652                                                                 }
7653
7654                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
7655
7656                                                                 player[numplayers].damagetolerance=200;
7657
7658                                                                 player[numplayers].protectionhead=player[0].protectionhead;
7659                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
7660                                                                 player[numplayers].protectionlow=player[0].protectionlow;
7661                                                                 player[numplayers].armorhead=player[0].armorhead;
7662                                                                 player[numplayers].armorhigh=player[0].armorhigh;
7663                                                                 player[numplayers].armorlow=player[0].armorlow;
7664                                                                 player[numplayers].metalhead=player[0].metalhead;
7665                                                                 player[numplayers].metalhigh=player[0].metalhigh;
7666                                                                 player[numplayers].metallow=player[0].metallow;
7667
7668                                                                 player[numplayers].immobile=player[0].immobile;
7669
7670                                                                 player[numplayers].numclothes=player[0].numclothes;
7671                                                                 if(player[numplayers].numclothes)
7672                                                                         for(i=0;i<player[numplayers].numclothes;i++){
7673                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
7674                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
7675                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
7676                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
7677                                                                                 tintr=player[numplayers].clothestintr[i];
7678                                                                                 tintg=player[numplayers].clothestintg[i];
7679                                                                                 tintb=player[numplayers].clothestintb[i];
7680                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7681                                                                         }
7682                                                                         if(player[numplayers].numclothes){
7683                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
7684                                                                         }
7685
7686                                                                         player[numplayers].power=player[0].power;
7687                                                                         player[numplayers].speedmult=player[0].speedmult;
7688
7689                                                                         player[numplayers].damage=0;
7690                                                                         player[numplayers].permanentdamage=0;
7691                                                                         player[numplayers].superpermanentdamage=0;
7692                                                                         player[numplayers].deathbleeding=0;
7693                                                                         player[numplayers].bleeding=0;
7694                                                                         player[numplayers].numwaypoints=0;
7695                                                                         player[numplayers].waypoint=0;
7696                                                                         player[numplayers].jumppath=0;
7697                                                                         player[numplayers].weaponstuck=-1;
7698                                                                         player[numplayers].weaponactive=-1;
7699                                                                         player[numplayers].num_weapons=0;
7700                                                                         player[numplayers].bloodloss=0;
7701                                                                         player[numplayers].dead=0;
7702
7703                                                                         player[numplayers].loaded=1;
7704
7705                                                                         numplayers++;
7706                                                         }
7707                                                         drawmodetogglekeydown=1;
7708                                                 }
7709
7710                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
7711                                                         if(player[numplayers-1].numwaypoints<90){
7712                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
7713                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
7714                                                                 player[numplayers-1].numwaypoints++;
7715                                                         }
7716                                                         drawmodetogglekeydown=1;
7717                                                 }
7718
7719                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7720                                                         if(numpathpoints<30){
7721                                                                 bool connected,alreadyconnected;
7722                                                                 connected=0;
7723                                                                 if(numpathpoints>1)
7724                                                                         for(i=0;i<numpathpoints;i++){
7725                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
7726                                                                                         alreadyconnected=0;
7727                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
7728                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
7729                                                                                         }
7730                                                                                         if(!alreadyconnected){
7731                                                                                                 numpathpointconnect[pathpointselected]++;
7732                                                                                                 connected=1;
7733                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
7734                                                                                         }
7735                                                                                 }
7736                                                                         }
7737                                                                         if(!connected){
7738                                                                                 numpathpoints++;
7739                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
7740                                                                                 numpathpointconnect[numpathpoints-1]=0;
7741                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
7742                                                                                         numpathpointconnect[pathpointselected]++;
7743                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
7744                                                                                 }
7745                                                                                 pathpointselected=numpathpoints-1;
7746                                                                         }
7747                                                         }
7748                                                         drawmodetogglekeydown=1;
7749                                                 }
7750
7751                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
7752                                                         pathpointselected++;
7753                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
7754                                                         drawmodetogglekeydown=1;
7755                                                 }
7756                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
7757                                                         pathpointselected--;
7758                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
7759                                                         drawmodetogglekeydown=1;
7760                                                 }
7761                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
7762                                                         if(pathpointselected!=-1){
7763                                                                 numpathpoints--;
7764                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
7765                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
7766                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
7767                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
7768                                                                 }
7769                                                                 for(i=0;i<numpathpoints;i++){
7770                                                                         for(j=0;j<numpathpointconnect[i];j++){
7771                                                                                 if(pathpointconnect[i][j]==pathpointselected){
7772                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
7773                                                                                         numpathpointconnect[i]--;
7774                                                                                 }
7775                                                                                 if(pathpointconnect[i][j]==numpathpoints){
7776                                                                                         pathpointconnect[i][j]=pathpointselected;
7777                                                                                 }
7778                                                                         }
7779                                                                 }
7780                                                                 pathpointselected=numpathpoints-1;
7781                                                         }
7782                                                         drawmodetogglekeydown=1;
7783                                                 }
7784
7785                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7786                                                         editorenabled=1-editorenabled;
7787                                                         if(editorenabled){
7788                                                                 player[0].damagetolerance=100000;
7789                                                                 player[0].damage=0;
7790                                                                 player[0].superpermanentdamage=0;
7791                                                                 player[0].bloodloss=0;
7792                                                                 player[0].deathbleeding=0;
7793                                                         }
7794                                                         if(!editorenabled){
7795                                                                 player[0].damagetolerance=200;
7796                                                                 player[0].damage=0;
7797                                                                 player[0].permanentdamage=0;
7798                                                                 player[0].superpermanentdamage=0;
7799                                                                 player[0].bloodloss=0;
7800                                                                 player[0].deathbleeding=0;
7801                                                         }
7802                                                         drawmodetogglekeydown=1;
7803                                                 }
7804
7805                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7806                                                         editortype--;
7807                                                         if(editortype==treeleavestype||editortype==10)editortype--;
7808                                                         if(editortype<0)editortype=firetype;
7809                                                         drawmodetogglekeydown=1;
7810                                                 }
7811
7812                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7813                                                         editortype++;
7814                                                         if(editortype==treeleavestype||editortype==10)editortype++;
7815                                                         if(editortype>firetype)editortype=0;
7816                                                         drawmodetogglekeydown=1;
7817                                                 }
7818
7819                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7820                                                         editorrotation-=multiplier*100;
7821                                                         if(editorrotation<-.01)editorrotation=-.01;
7822                                                         drawmodetogglekeydown=1;
7823                                                 }
7824
7825                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7826                                                         editorrotation+=multiplier*100;
7827                                                         drawmodetogglekeydown=1;
7828                                                 }
7829
7830                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7831                                                         editorsize+=multiplier;
7832                                                         drawmodetogglekeydown=1;
7833                                                 }
7834
7835                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7836                                                         editorsize-=multiplier;
7837                                                         if(editorsize<.1)editorsize=.1;
7838                                                         drawmodetogglekeydown=1;
7839                                                 }
7840
7841
7842                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7843                                                         mapradius-=multiplier*10;
7844                                                 }
7845
7846                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7847                                                         mapradius+=multiplier*10;
7848                                                 }
7849                                                 /*
7850                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7851                                                 mapcenter.x+=multiplier*20;
7852                                                 }
7853
7854                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7855                                                 mapcenter.x-=multiplier*20;
7856                                                 }
7857
7858                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7859                                                 mapcenter.z+=multiplier*20;
7860                                                 }
7861
7862                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7863                                                 mapcenter.z-=multiplier*20;
7864                                                 }
7865                                                 */
7866                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7867                                                         editorrotation2+=multiplier*100;
7868                                                 }
7869
7870                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7871                                                         editorrotation2-=multiplier*100;
7872                                                         if(editorrotation2<-.01)editorrotation2=-.01;
7873                                                 }
7874                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7875                                                         int closest=-1;
7876                                                         float closestdist=-1;
7877                                                         float distance;
7878                                                         for(i=0;i<objects.numobjects;i++){
7879                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
7880                                                                 if(closestdist==-1||distance<closestdist){
7881                                                                         closestdist=distance;
7882                                                                         closest=i;
7883                                                                 }
7884                                                         }
7885                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
7886                                                         drawmodetogglekeydown=1;
7887                                                 }
7888
7889
7890                                                 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)){
7891                                                         drawmodetogglekeydown=0;
7892                                                 }
7893
7894                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
7895                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
7896                                                         player[0].RagDoll(0);
7897                                                         //player[0].spurt=1;
7898                                                         //player[0].DoDamage(1000);
7899
7900                                                         float gLoc[3];
7901                                                         float vel[3];
7902                                                         gLoc[0]=player[0].coords.x;
7903                                                         gLoc[1]=player[0].coords.y;
7904                                                         gLoc[2]=player[0].coords.z;
7905                                                         vel[0]=player[0].velocity.x;
7906                                                         vel[1]=player[0].velocity.y;
7907                                                         vel[2]=player[0].velocity.z;
7908                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
7909                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
7910                                                         OPENAL_SetVolume(channels[whooshsound], 128);
7911                                                         OPENAL_SetPaused(channels[whooshsound], false);
7912                                                         //OPENAL_SetPaused(channels[whooshsound], true);
7913
7914                                                         texturesizetogglekeydown=1;
7915                                                 }
7916
7917                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
7918
7919                                                         int closest=-1;
7920                                                         float closestdist=-1;
7921                                                         float distance;
7922                                                         for(i=0;i<objects.numobjects;i++){
7923                                                                 if(objects.type[i]==treeleavestype){
7924                                                                         objects.scale[i]*=.9;
7925                                                                 }
7926                                                         }
7927                                                         texturesizetogglekeydown=1;
7928                                                 }
7929
7930                                                 static XYZ relative;
7931                                                 static int randattack;
7932                                                 //Attack
7933                                                 static bool playerrealattackkeydown=0;
7934
7935                                                 if(!buttons[0])oldbutton=0;
7936                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
7937                                                 if(oldattackkey)player[0].attackkeydown=0;
7938                                                 if(oldattackkey)playerrealattackkeydown=0;
7939                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
7940                                                 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);
7941                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
7942                                                         for(k=0;k<numplayers;k++){
7943                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
7944                                                                         player[k].Reverse();
7945                                                         }
7946                                                 }
7947
7948                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
7949
7950                                                 for(k=0;k<numplayers;k++){
7951                                                         if(indialogue!=-1)player[k].attackkeydown=0;
7952                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
7953                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
7954                                                                 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)){
7955                                                                         player[k].jumppower-=2;
7956                                                                 }
7957                                                                 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)){
7958                                                                         for(i=0;i<numplayers;i++){
7959                                                                                 if(i==k)i++;
7960                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
7961                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
7962                                                                                                 player[k].targetanimation=dodgebackanim;
7963                                                                                                 player[k].target=0;
7964                                                                                                 player[k].targetframe=0;
7965                                                                                                 rotatetarget=player[i].coords-player[k].coords;
7966                                                                                                 Normalise(&rotatetarget);
7967                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
7968                                                                                                 player[k].targetrotation*=360/6.28;
7969                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
7970
7971                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
7972                                                                                         }
7973                                                                         }
7974                                                                         if(player[k].targetanimation!=dodgebackanim){
7975                                                                                 if(k==0)numflipped++;
7976                                                                                 player[k].targetanimation=backhandspringanim;
7977                                                                                 player[k].target=0;
7978                                                                                 player[k].targetframe=0;
7979                                                                                 player[k].targetrotation=-rotation+180;
7980                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
7981                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
7982                                                                                 player[k].rotation=player[k].targetrotation;
7983                                                                                 player[k].jumppower-=2;
7984                                                                         }
7985                                                                 }
7986                                                                 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())){
7987                                                                         player[k].hasvictim=0;
7988                                                                         if(numplayers>1)
7989                                                                                 for(i=0;i<numplayers;i++){
7990                                                                                         if(i==k)i++;
7991                                                                                         if(!player[k].hasvictim)
7992                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
7993                                                                                                         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){
7994                                                                                                                 player[k].victim=&player[i];
7995                                                                                                                 player[k].hasvictim=1;
7996                                                                                                                 if(player[k].aitype==playercontrolled){
7997                                                                                                                         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;
7998                                                                                                                         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;
7999                                                                                                                         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;
8000                                                                                                                         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;
8001                                                                                                                         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;
8002                                                                                                                         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;
8003                                                                                                                         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;
8004                                                                                                                         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;
8005                                                                                                                         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;
8006                                                                                                                         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;
8007                                                                                                                 }
8008                                                                                                                 else {
8009                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8010                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8011                                                                                                                                 else randattack=abs(Random()%5);
8012                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8013                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8014                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8015                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8016                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8017                                                                                                                                 }
8018                                                                                                                                 if(player[k].weaponactive!=-1){
8019                                                                                                                                         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;
8020                                                                                                                                         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;
8021                                                                                                                                         //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;
8022                                                                                                                                         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;
8023                                                                                                                                         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;
8024                                                                                                                                         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;
8025                                                                                                                                         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;
8026                                                                                                                                         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;
8027                                                                                                                                 }
8028                                                                                                                         }
8029                                                                                                                 }
8030                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8031                                                                                                         }
8032                                                                                                         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)){
8033                                                                                                                 if(player[k].weaponactive==-1){
8034                                                                                                                         player[i].targetanimation=sneakattackedanim;
8035                                                                                                                         player[i].currentanimation=sneakattackedanim;
8036                                                                                                                         player[k].currentanimation=sneakattackanim;
8037                                                                                                                         player[k].targetanimation=sneakattackanim;
8038                                                                                                                         player[k].oldcoords=player[k].coords;
8039                                                                                                                         player[k].coords=player[i].coords;
8040                                                                                                                 }
8041                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8042                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8043                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8044                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8045                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8046                                                                                                                         player[i].oldcoords=player[i].coords;
8047                                                                                                                         player[i].coords=player[k].coords;
8048                                                                                                                 }
8049                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8050                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8051                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8052                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8053                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8054                                                                                                                         player[i].oldcoords=player[i].coords;
8055                                                                                                                         player[i].coords=player[k].coords;
8056                                                                                                                 }
8057                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8058                                                                                                                         player[k].victim=&player[i];
8059                                                                                                                         player[k].hasvictim=1;
8060                                                                                                                         player[i].targettilt2=0;
8061                                                                                                                         player[i].targetframe=1;
8062                                                                                                                         player[i].currentframe=0;
8063                                                                                                                         player[i].target=0;
8064                                                                                                                         player[i].velocity=0;
8065                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8066                                                                                                                         player[k].currentframe=player[i].currentframe;
8067                                                                                                                         player[k].targetframe=player[i].targetframe;
8068                                                                                                                         player[k].target=player[i].target;
8069                                                                                                                         player[k].velocity=0;
8070                                                                                                                         player[k].targetrotation=player[i].rotation;
8071                                                                                                                         player[k].rotation=player[i].rotation;
8072                                                                                                                         player[i].targetrotation=player[i].rotation;
8073                                                                                                                 }
8074                                                                                                         }
8075                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8076                                                                                                                 oldattackkey=1;
8077                                                                                                                 player[k].targetframe=0;
8078                                                                                                                 player[k].target=0;
8079                                                                                                                 //player[k].velocity=0;
8080
8081                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8082                                                                                                                 Normalise(&rotatetarget);
8083                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8084                                                                                                                 player[k].targetrotation*=360/6.28;
8085                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8086
8087                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8088
8089                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8090                                                                                                                 player[k].lastattack2=player[k].lastattack;
8091                                                                                                                 player[k].lastattack=player[k].targetanimation;
8092                                                                                                                 //player[k].targettilt2=0;
8093                                                                                                                 //slomo=1;
8094                                                                                                                 //slomodelay=.2;
8095                                                                                                         }
8096                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8097                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8098                                                                                                                 Normalise(&rotatetarget);
8099                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8100                                                                                                                 player[k].targetrotation*=360/6.28;
8101                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8102                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8103                                                                                                                 oldattackkey=1;
8104                                                                                                                 player[k].victim=&player[i];
8105                                                                                                                 player[k].hasvictim=1;
8106                                                                                                                 player[i].targetanimation=knifefollowedanim;
8107                                                                                                                 player[i].currentanimation=knifefollowedanim;
8108                                                                                                                 player[i].targettilt2=0;
8109                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8110                                                                                                                 player[i].targetframe=1;
8111                                                                                                                 player[i].currentframe=0;
8112                                                                                                                 player[i].target=0;
8113                                                                                                                 player[i].velocity=0;
8114                                                                                                                 player[k].currentanimation=knifefollowanim;
8115                                                                                                                 player[k].targetanimation=knifefollowanim;
8116                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8117                                                                                                                 player[k].currentframe=player[i].currentframe;
8118                                                                                                                 player[k].targetframe=player[i].targetframe;
8119                                                                                                                 player[k].target=player[i].target;
8120                                                                                                                 player[k].velocity=0;
8121                                                                                                                 player[k].oldcoords=player[k].coords;
8122                                                                                                                 player[i].coords=player[k].coords;
8123                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8124                                                                                                                 player[i].rotation=player[k].targetrotation;
8125                                                                                                                 player[k].rotation=player[k].targetrotation;
8126                                                                                                                 player[i].rotation=player[k].targetrotation;
8127                                                                                                         }
8128                                                                                                 }
8129                                                                                 }
8130                                                                                 bool hasstaff=0;
8131                                                                                 if(player[k].weaponactive!=-1){
8132                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8133                                                                                 }
8134                                                                                 if(numplayers>1)
8135                                                                                         for(i=0;i<numplayers;i++){
8136                                                                                                 if(i==k)i++;
8137                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
8138                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8139                                                                                                                 if(player[i].skeleton.free)
8140                                                                                                                         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)))){
8141                                                                                                                                 player[k].victim=&player[i];
8142                                                                                                                                 player[k].hasvictim=1;
8143                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8144                                                                                                                                         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;
8145                                                                                                                                         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;
8146                                                                                                                                         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;
8147                                                                                                                                 }
8148                                                                                                                                 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){
8149                                                                                                                                         player[k].targetanimation=killanim;
8150                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8151                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8152                                                                                                                                                         terrain.DeleteDecal(j);
8153                                                                                                                                                 }
8154                                                                                                                                         }
8155                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8156                                                                                                                                                 if(objects.model[l].type==decalstype)
8157                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8158                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8159                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8160                                                                                                                                                                 }
8161                                                                                                                                                         }
8162                                                                                                                                         }
8163                                                                                                                                 }
8164                                                                                                                                 if(!player[i].dead||musictype!=2)
8165                                                                                                                                         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)){
8166                                                                                                                                                 player[k].targetanimation=dropkickanim;
8167                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8168                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8169                                                                                                                                                                 terrain.DeleteDecal(j);
8170                                                                                                                                                         }
8171                                                                                                                                                 }
8172                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8173                                                                                                                                                         if(objects.model[l].type==decalstype)
8174                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8175                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8176                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8177                                                                                                                                                                         }
8178                                                                                                                                                                 }
8179                                                                                                                                                 }
8180                                                                                                                                         }
8181                                                                                                                         }
8182                                                                                                                         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)){
8183                                                                                                                                 oldattackkey=1;
8184                                                                                                                                 player[k].targetframe=0;
8185                                                                                                                                 player[k].target=0;
8186                                                                                                                                 //player[k].velocity=0;
8187
8188                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8189                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8190                                                                                                                                         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;
8191                                                                                                                                 }
8192                                                                                                                                 Normalise(&rotatetarget);
8193                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8194                                                                                                                                 player[k].targetrotation*=360/6.28;
8195                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8196
8197                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8198                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8199                                                                                                                                 }
8200
8201                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8202                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8203
8204                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8205                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8206                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8207
8208                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8209                                                                                                                                         player[k].targetrotation+=30;
8210                                                                                                                                 }
8211                                                                                                                                 //player[k].targettilt2=0;
8212                                                                                                                                 //slomo=1;
8213                                                                                                                                 //slomodelay=.2;
8214                                                                                                                         }
8215                                                                                                 }
8216                                                                                         }
8217                                                                                         if(!player[k].hasvictim){
8218                                                                                                 for(i=0;i<numplayers;i++){
8219                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8220                                                                                                                 player[k].victim=&player[i];
8221                                                                                                                 player[k].hasvictim=1;
8222                                                                                                         }
8223                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8224                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8225                                                                                                                         player[k].victim=&player[i];
8226                                                                                                                 }
8227                                                                                                 }
8228                                                                                         }
8229                                                                                         if(player[k].aitype==playercontrolled)
8230                                                                                                 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)){
8231                                                                                                         oldattackkey=1;
8232                                                                                                         player[k].targetanimation=rabbitkickanim;
8233                                                                                                         player[k].targetframe=0;
8234                                                                                                         player[k].target=0;
8235                                                                                                 }
8236                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8237                                                                                                         numattacks++;
8238                                                                                                         bool armedstaff=0;
8239                                                                                                         if(player[k].weaponactive!=-1){
8240                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8241                                                                                                         }
8242                                                                                                         bool armedsword=0;
8243                                                                                                         if(player[k].weaponactive!=-1){
8244                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8245                                                                                                         }
8246                                                                                                         bool armedknife=0;
8247                                                                                                         if(player[k].weaponactive!=-1){
8248                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8249                                                                                                         }
8250                                                                                                         if(armedstaff)numstaffattack++;
8251                                                                                                         else if(armedsword)numswordattack++;
8252                                                                                                         else if(armedknife)numknifeattack++;
8253                                                                                                         else numunarmedattack++;
8254                                                                                                 }
8255                                                                 }
8256                                                         }
8257                                                 }
8258
8259                                                 //Collisions
8260                                                 static float collisionradius;
8261                                                 if(numplayers>1)
8262                                                         for(k=0;k<numplayers;k++){
8263                                                                 for(i=k;i<numplayers;i++){
8264                                                                         if(i==k)i++;
8265                                                                         if(i<numplayers)
8266                                                                                 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))
8267                                                                                         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))
8268                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8269                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8270                                                                                                                 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)
8271                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8272                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8273                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8274                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8275                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8276                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8277                                                                                                                                                                         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)){
8278                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8279                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8280                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8281                                                                                                                                                                                 }
8282                                                                                                                                                                         }
8283
8284                                                                                                                                                                         tempcoords1=player[i].coords;
8285                                                                                                                                                                         tempcoords2=player[k].coords;
8286                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8287                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8288                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8289                                                                                                                                                                         if(player[0].hasvictim)
8290                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8291                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
8292                                                                                                                                                                                 if(k==0)
8293                                                                                                                                                                                         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)){
8294                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8295                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8296                                                                                                                                                                                                 player[i].skeleton.free=0;
8297                                                                                                                                                                                                 player[i].rotation=0;
8298                                                                                                                                                                                                 player[i].RagDoll(0);
8299                                                                                                                                                                                                 player[i].DoDamage(20);
8300                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8301                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8302                                                                                                                                                                                                 player[k].lastcollide=1;
8303                                                                                                                                                                                         }
8304                                                                                                                                                                                         if(i==0)
8305                                                                                                                                                                                                 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)){
8306                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8307                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8308                                                                                                                                                                                                         player[k].skeleton.free=0;
8309                                                                                                                                                                                                         player[k].rotation=0;
8310                                                                                                                                                                                                         player[k].RagDoll(0);
8311                                                                                                                                                                                                         player[k].DoDamage(20);
8312                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8313                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8314                                                                                                                                                                                                         player[i].lastcollide=1;
8315                                                                                                                                                                                                 }
8316
8317                                                                                                                                                                                                 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)){
8318                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8319                                                                                                                                                                                                         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))
8320                                                                                                                                                                                                                 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))){
8321                                                                                                                                                                                                                         //If hit by body
8322                                                                                                                                                                                                                         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)){
8323                                                                                                                                                                                                                                 static float gLoc[3];
8324                                                                                                                                                                                                                                 static float vel[3];
8325                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8326                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8327                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8328                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8329                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8330                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8331                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8332                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
8333                                                                                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8334                                                                                                                                                                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 256);
8335                                                                                                                                                                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
8336                                                                                                                                                                                                                                 }
8337                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8338                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8339
8340                                                                                                                                                                                                                                 player[i].RagDoll(0);
8341                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8342                                                                                                                                                                                                                                         bonus=aimbonus;
8343                                                                                                                                                                                                                                         bonustime=0;
8344                                                                                                                                                                                                                                         bonusvalue=150;
8345                                                                                                                                                                                                                                 }
8346                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8347                                                                                                                                                                                                                                 player[k].RagDoll(0);
8348                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8349                                                                                                                                                                                                                                         bonus=aimbonus;
8350                                                                                                                                                                                                                                         bonustime=0;
8351                                                                                                                                                                                                                                         bonusvalue=150;
8352                                                                                                                                                                                                                                 }
8353                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8354
8355                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8356                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8357                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8358                                                                                                                                                                                                                                 }
8359                                                                                                                                                                                                                                 //}
8360                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8361                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8362                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8363                                                                                                                                                                                                                                 }
8364                                                                                                                                                                                                                                 //}
8365
8366                                                                                                                                                                                                                         }
8367                                                                                                                                                                                                                 }
8368                                                                                                                                                                                                                 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)){
8369                                                                                                                                                                                                                         //If bumped
8370                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8371                                                                                                                                                                                                                                 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)){
8372                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8373                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8374                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8375                                                                                                                                                                                                                                         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);
8376                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8377                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8378                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8379                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8380                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8381                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8382                                                                                                                                                                                                                                                                 player[k].target=0;
8383                                                                                                                                                                                                                                                         }
8384                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8385                                                                                                                                                                                                                                                         {
8386                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8387                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8388                                                                                                                                                                                                                                                                 player[k].target=0;
8389                                                                                                                                                                                                                                                         }
8390                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8391                                                                                                                                                                                                                                                 }
8392                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8393                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8394                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8395                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8396                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8397                                                                                                                                                                                                                                                                         player[i].target=0;
8398                                                                                                                                                                                                                                                                 }
8399                                                                                                                                                                                                                                                                 else
8400                                                                                                                                                                                                                                                                 {
8401                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8402                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8403                                                                                                                                                                                                                                                                         player[i].target=0;
8404                                                                                                                                                                                                                                                                 }
8405                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8406                                                                                                                                                                                                                                                         }
8407                                                                                                                                                                                                                                 }
8408                                                                                                                                                                                                                                 if(hostile){
8409                                                                                                                                                                                                                                         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){
8410                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8411                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8412                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8413                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8414                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8415                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8416                                                                                                                                                                                                                                                 player[k].lastcollide=1;
8417                                                                                                                                                                                                                                                 if(k==0){
8418                                                                                                                                                                                                                                                         bonus=AboveBonus;
8419                                                                                                                                                                                                                                                         bonustime=0;
8420                                                                                                                                                                                                                                                         bonusvalue=50;
8421                                                                                                                                                                                                                                                 }
8422                                                                                                                                                                                                                                         }
8423                                                                                                                                                                                                                                         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){
8424                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8425                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8426                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8427                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8428                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8429                                                                                                                                                                                                                                                 player[k].RagDoll(0);
8430                                                                                                                                                                                                                                                 player[i].lastcollide=1;
8431                                                                                                                                                                                                                                                 if(i==0){
8432                                                                                                                                                                                                                                                         bonus=AboveBonus;
8433                                                                                                                                                                                                                                                         bonustime=0;
8434                                                                                                                                                                                                                                                         bonusvalue=50;
8435                                                                                                                                                                                                                                                 }
8436                                                                                                                                                                                                                                         }
8437                                                                                                                                                                                                                                 }
8438                                                                                                                                                                                                                         }
8439                                                                                                                                                                                                                 }
8440                                                                                                                                                                                                 }
8441                                                                                                                                                                                                 player[i].CheckKick();
8442                                                                                                                                                                                                 player[k].CheckKick();
8443                                                                                                                                                                         }
8444                                                                                                                                                                 }
8445                                                                 }
8446                                                         }
8447
8448                                                         for(k=0;k<numplayers;k++){
8449                                                                 for(i=k;i<numplayers;i++){
8450                                                                         if(i==k)i++;
8451                                                                         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))){
8452                                                                                 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)){
8453                                                                                         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)){
8454                                                                                                 player[i].victim=&player[k];
8455                                                                                                 player[i].targetanimation=jumpreversedanim;
8456                                                                                                 player[i].currentanimation=jumpreversedanim;
8457                                                                                                 player[k].currentanimation=jumpreversalanim;
8458                                                                                                 player[k].targetanimation=jumpreversalanim;
8459                                                                                                 player[i].targettilt2=0;
8460                                                                                                 player[i].currentframe=0;
8461                                                                                                 player[i].targetframe=1;
8462                                                                                                 player[k].currentframe=0;
8463                                                                                                 player[k].targetframe=1;
8464                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8465                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8466                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8467                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8468                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8469                                                                                                         player[k].currentframe=1;
8470                                                                                                         player[k].targetframe=2;
8471                                                                                                         player[i].currentframe=1;
8472                                                                                                         player[i].targetframe=2;
8473                                                                                                 }
8474                                                                                                 player[k].targettilt2=0;
8475                                                                                                 player[i].target=0;
8476                                                                                                 player[i].velocity=0;
8477                                                                                                 player[k].velocity=0;
8478                                                                                                 player[k].oldcoords=player[k].coords;
8479                                                                                                 player[i].coords=player[k].coords;
8480                                                                                                 player[k].targetrotation=player[i].targetrotation;
8481                                                                                                 player[k].rotation=player[i].targetrotation;
8482                                                                                                 player[k].victim=&player[i];
8483                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8484                                                                                         }
8485                                                                                         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)){
8486                                                                                                 player[k].victim=&player[i];
8487                                                                                                 player[k].targetanimation=jumpreversedanim;
8488                                                                                                 player[k].currentanimation=jumpreversedanim;
8489                                                                                                 player[i].currentanimation=jumpreversalanim;
8490                                                                                                 player[i].targetanimation=jumpreversalanim;
8491                                                                                                 player[k].targettilt2=0;
8492                                                                                                 player[i].targettilt2=0;
8493                                                                                                 player[k].currentframe=0;
8494                                                                                                 player[k].targetframe=1;
8495                                                                                                 player[i].currentframe=0;
8496                                                                                                 player[i].targetframe=1;
8497                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8498                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8499                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8500                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8501                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8502                                                                                                         player[k].currentframe=1;
8503                                                                                                         player[k].targetframe=2;
8504                                                                                                         player[i].currentframe=1;
8505                                                                                                         player[i].targetframe=2;
8506                                                                                                 }
8507                                                                                                 player[k].target=0;
8508                                                                                                 player[k].velocity=0;
8509                                                                                                 player[i].velocity=0;
8510                                                                                                 player[i].oldcoords=player[i].coords;
8511                                                                                                 player[k].coords=player[i].coords;
8512                                                                                                 player[i].targetrotation=player[k].targetrotation;
8513                                                                                                 player[i].rotation=player[k].targetrotation;
8514                                                                                                 player[i].victim=&player[k];
8515                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8516                                                                                         }
8517                                                                                 }
8518                                                                         }
8519                                                                 }
8520                                                         }
8521
8522                                                         for(k=0;k<numplayers;k++)
8523                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8524
8525
8526                                                         //pile
8527                                                         /*
8528                                                         XYZ tempdiff;
8529                                                         XYZ tempoldpos;
8530                                                         XYZ temp1,temp2;
8531                                                         bool isgood;
8532                                                         static float checkdelay;
8533                                                         checkdelay-=multiplier;
8534                                                         int m;
8535                                                         static bool checkedcoll[maxplayers][maxplayers];
8536                                                         static bool above[maxplayers];
8537
8538                                                         for(i=0;i<maxplayers;i++){
8539                                                         for(j=0;j<maxplayers;j++){
8540                                                         checkedcoll[i][j]=0;
8541                                                         }
8542                                                         }
8543
8544                                                         if(numplayers>1&&checkdelay<=0){
8545                                                         checkdelay=.015;
8546                                                         for(k=0;k<numplayers;k++){
8547                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8548
8549                                                         for(i=k;i<numplayers;i++){
8550                                                         if(i==k)i++;
8551                                                         if(i<numplayers)
8552                                                         if(!checkedcoll[i][k]){
8553                                                         checkedcoll[i][k]=1;
8554                                                         checkedcoll[k][i]=1;
8555                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8556                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8557                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8558                                                         if(player[i].coords.y>player[k].coords.y-3)
8559                                                         if(player[i].coords.y<player[k].coords.y+3)
8560                                                         if(player[i].coords.x>player[k].coords.x-3)
8561                                                         if(player[i].coords.x<player[k].coords.x+3)
8562                                                         if(player[i].coords.z>player[k].coords.z-3)
8563                                                         if(player[i].coords.z<player[k].coords.z+3)
8564                                                         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)){
8565                                                         int stuck,moving;
8566                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8567                                                         stuck=i;
8568                                                         moving=k;
8569                                                         }
8570                                                         else
8571                                                         {
8572                                                         moving=i;
8573                                                         stuck=k;
8574                                                         }
8575                                                         isgood=1;
8576
8577                                                         if(isgood){
8578                                                         above[moving]=stuck;
8579                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8580                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8581                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8582                                                         {
8583                                                         player[moving].skeleton.joints[l].position.y+=.003;
8584                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8585
8586                                                         }
8587                                                         }
8588                                                         }
8589                                                         }
8590                                                         }
8591                                                         }
8592                                                         }
8593                                                         }
8594                                                         }
8595
8596                                                         */
8597
8598                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
8599                                                                 texturesizetogglekeydown=0;
8600                                                         }
8601
8602                                                         for(k=0;k<numplayers;k++){
8603                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8604                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8605                                                                                 player[k].DoDamage(1000);
8606                                                                         }
8607                                                                 }
8608                                                         }
8609
8610                                                         static bool respawnkeydown;
8611                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
8612                                                                 targetlevel=whichlevel;
8613                                                                 loading=1;
8614                                                                 leveltime=5;
8615                                                         }
8616                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
8617                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
8618
8619
8620
8621
8622                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
8623                                                                 targetlevel++;
8624                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
8625                                                                 loading=1;
8626                                                                 leveltime=5;
8627                                                                 slomotogglekeydown=1;
8628                                                         }
8629
8630                                                         /*
8631                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
8632                                                         //Respawn
8633                                                         OPENAL_SetPaused(channels[whooshsound], true);
8634                                                         changedelay=0;
8635                                                         for(k=0;k<numplayers;k++){
8636                                                         player[k].dead=0;
8637                                                         player[k].damage=0;
8638                                                         player[k].permanentdamage=0;
8639                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
8640                                                         player[k].aitype=passivetype;
8641                                                         }
8642                                                         player[0].aitype=playercontrolled;
8643                                                         }
8644                                                         */
8645
8646                                                         static bool movekey;
8647                                                         static bool connected;
8648                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
8649                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
8650                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
8651                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
8652                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
8653                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
8654
8655                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
8656
8657                 for(int i=0;i<numplayers;i++){
8658                                                                 if(!player[i].skeleton.free){
8659                                                                         oldtargetrotation=player[i].targetrotation;
8660                                                                         if(i==0&&indialogue==-1){
8661                                                                                 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){
8662                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
8663                                                                                         if(cameramode)player[0].targetrotation=0;
8664                                                                                 }
8665
8666                                                                                 facing=0;
8667                                                                                 facing.z=-1;
8668
8669                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
8670                                                                                 if(cameramode){facing=flatfacing;}
8671                                                                                 else{
8672                                                                                         facing=DoRotation(facing,-rotation2,0,0);
8673                                                                                         facing=DoRotation(facing,0,0-rotation,0);
8674                                                                                 }
8675
8676                                                                                 player[0].lookrotation=-rotation;
8677
8678                                                                                 player[i].targetheadrotation=rotation;
8679                                                                                 player[i].targetheadrotation2=rotation2;
8680                                                                         }
8681                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
8682                                                                                 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){
8683                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
8684                                                                                 }
8685
8686                                                                                 facing=0;
8687                                                                                 facing.z=-1;
8688
8689                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
8690
8691                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
8692                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
8693
8694                                                                                 player[i].targetheadrotation=player[i].lookrotation;
8695                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;
8696                                                                         }
8697                                                                         if(indialogue!=-1){
8698                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
8699                                                                                 Normalise(&rotatetarget);
8700                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
8701                                                                                 player[i].targetheadrotation*=360/6.28;
8702                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
8703
8704                                                                                 player[i].targetheadrotation*=-1;
8705                                                                                 player[i].targetheadrotation+=180;
8706                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
8707                                                                         }
8708
8709                                                                         bool pause;
8710
8711                                                                         if(leveltime<.5)
8712                                                                                 numenvsounds=0;
8713
8714                                                                         player[i].avoidsomething=0;
8715
8716                                                                         for(j=0;j<objects.numobjects;j++){
8717                                                                                 if(objects.onfire[j]){
8718                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
8719                                                                                         {
8720                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
8721                                                                                                         player[i].collided=0;
8722                                                                                                         player[i].avoidcollided=1;
8723                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
8724                                                                                                                 player[i].avoidwhere=objects.position[j];
8725                                                                                                 }
8726                                                                                         }
8727                                                                                 }
8728                                                                         }
8729
8730                                                                         //Add avoidwhere to players
8731
8732                                                                         for(j=0;j<numplayers;j++){
8733                                                                                 if(player[j].onfire){
8734                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
8735                                                                                         {
8736                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
8737                                                                                                         player[i].collided=0;
8738                                                                                                         player[i].avoidcollided=1;
8739                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
8740                                                                                                                 player[i].avoidwhere=objects.position[j];
8741                                                                                                 }
8742                                                                                         }
8743                                                                                 }
8744                                                                         }
8745
8746                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
8747                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
8748                                                                                 player[i].jumpclimb=0;
8749                                                                                 //AI
8750                                                                                 if(editorenabled)player[i].stunned=1;
8751
8752                                                                                 player[i].pause=0;
8753                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
8754                                                                                 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;
8755
8756                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
8757                                                                                 player[i].forwardkeydown=0;
8758                                                                                 player[i].leftkeydown=0;
8759                                                                                 player[i].backkeydown=0;
8760                                                                                 player[i].rightkeydown=0;
8761                                                                                 player[i].crouchkeydown=0;
8762                                                                                 player[i].attackkeydown=0;
8763                                                                                 player[i].jumpkeydown=0;
8764                                                                                 player[i].throwkeydown=0;
8765                                                                                 }*/
8766
8767                                                                                 if(player[i].aitype==pathfindtype){
8768                                                                                         if(player[i].finalpathfindpoint==-1){
8769                                                                                                 float closestdistance;
8770                                                                                                 float tempdist;
8771                                                                                                 int closest;
8772                                                                                                 XYZ colpoint;
8773                                                                                                 closest=-1;
8774                                                                                                 closestdistance=-1;
8775                                                                                                 for(j=0;j<numpathpoints;j++){
8776                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
8777                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
8778                                                                                                                 closest=j;
8779                                                                                                                 player[i].finaltarget=pathpoint[j];
8780                                                                                                         }
8781                                                                                                 }
8782                                                                                                 player[i].finalpathfindpoint=closest;
8783                                                                                                 for(j=0;j<numpathpoints;j++){
8784                                                                                                         if(numpathpointconnect[j])
8785                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8786                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
8787                                                                                                                         if(tempdist*tempdist<closestdistance){
8788                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
8789                                                                                                                                         closestdistance=tempdist*tempdist;
8790                                                                                                                                         closest=j;
8791                                                                                                                                         player[i].finaltarget=colpoint;
8792                                                                                                                                 }
8793                                                                                                                         }
8794                                                                                                                 }
8795                                                                                                 }
8796                                                                                                 player[i].finalpathfindpoint=closest;
8797
8798                                                                                         }
8799                                                                                         if(player[i].targetpathfindpoint==-1){
8800                                                                                                 float closestdistance;
8801                                                                                                 float tempdist;
8802                                                                                                 int closest;
8803                                                                                                 XYZ colpoint;
8804                                                                                                 closest=-1;
8805                                                                                                 closestdistance=-1;
8806                                                                                                 if(player[i].lastpathfindpoint==-1){
8807                                                                                                         for(j=0;j<numpathpoints;j++){
8808                                                                                                                 if(j!=player[i].lastpathfindpoint)
8809                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
8810                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
8811                                                                                                                                 closest=j;
8812                                                                                                                         }
8813                                                                                                         }
8814                                                                                                         player[i].targetpathfindpoint=closest;
8815                                                                                                         for(j=0;j<numpathpoints;j++){
8816                                                                                                                 if(j!=player[i].lastpathfindpoint)
8817                                                                                                                         if(numpathpointconnect[j])
8818                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8819                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
8820                                                                                                                                         if(tempdist*tempdist<closestdistance){
8821                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
8822                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
8823                                                                                                                                                         closestdistance=tempdist*tempdist;
8824                                                                                                                                                         closest=j;
8825                                                                                                                                                         //}
8826                                                                                                                                                 }
8827                                                                                                                                         }
8828                                                                                                                                 }
8829                                                                                                         }
8830                                                                                                         player[i].targetpathfindpoint=closest;
8831                                                                                                 }
8832                                                                                                 else
8833                                                                                                 {
8834                                                                                                         for(j=0;j<numpathpoints;j++){
8835                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
8836                                                                                                                 {
8837                                                                                                                         connected=0;
8838                                                                                                                         if(numpathpointconnect[j])
8839                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8840                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
8841                                                                                                                                 }
8842                                                                                                                                 if(!connected)
8843                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
8844                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
8845                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
8846                                                                                                                                                 }
8847                                                                                                                                                 if(connected){
8848                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
8849                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
8850                                                                                                                                                                 closestdistance=tempdist;
8851                                                                                                                                                                 closest=j;
8852                                                                                                                                                         }
8853                                                                                                                                                 }
8854                                                                                                                 }
8855                                                                                                         }
8856                                                                                                         player[i].targetpathfindpoint=closest;
8857                                                                                                 }
8858                                                                                         }
8859                                                                                         player[i].losupdatedelay-=multiplier;
8860
8861                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
8862                                                                                         Normalise(&rotatetarget);
8863                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
8864                                                                                         player[i].targetrotation*=360/6.28;
8865                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
8866                                                                                         player[i].lookrotation=player[i].targetrotation;
8867                                                                                         //player[i].aiupdatedelay=.05;
8868
8869                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
8870                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
8871                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
8872                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
8873                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
8874                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
8875                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
8876                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
8877                                                                                                 player[i].targetpathfindpoint=-1;
8878                                                                                         }
8879                                                                                         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){
8880                                                                                                 player[i].aitype=passivetype;
8881                                                                                         }
8882
8883                                                                                         player[i].forwardkeydown=1;
8884                                                                                         player[i].leftkeydown=0;
8885                                                                                         player[i].backkeydown=0;
8886                                                                                         player[i].rightkeydown=0;
8887                                                                                         player[i].crouchkeydown=0;
8888                                                                                         player[i].attackkeydown=0;
8889                                                                                         player[i].throwkeydown=0;
8890
8891                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
8892
8893                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
8894                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
8895
8896                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
8897                                                                                                 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))
8898                                                                                                         player[i].aitype=attacktypecutoff;
8899                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
8900                                                                                                         player[i].aitype=attacktypecutoff;
8901
8902                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
8903                                                                                                         player[i].losupdatedelay=.2;
8904                                                                                                         for(j=0;j<numplayers;j++){
8905                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
8906                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
8907                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
8908                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
8909                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
8910                                                                                                                                                         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)){
8911                                                                                                                                                                 player[i].aitype=searchtype;
8912                                                                                                                                                                 player[i].lastchecktime=12;
8913                                                                                                                                                                 player[i].lastseen=player[j].coords;
8914                                                                                                                                                                 player[i].lastseentime=12;
8915                                                                                                                                                         }
8916                                                                                                                 }
8917                                                                                                         }
8918                                                                                                 }
8919                                                                                         }
8920                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
8921                                                                                                 if(player[i].creature!=wolftype){
8922                                                                                                         player[i].stunned=.6;
8923                                                                                                         player[i].surprised=.6;
8924                                                                                                 }
8925                                                                                         }
8926                                                                                 }
8927
8928                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
8929                                                                                         player[i].howactive=typeactive;
8930                                                                                 }
8931
8932                                                                                 if(player[i].aitype==passivetype){
8933                                                                                         player[i].aiupdatedelay-=multiplier;
8934                                                                                         player[i].losupdatedelay-=multiplier;
8935                                                                                         player[i].lastseentime+=multiplier;
8936                                                                                         player[i].pausetime-=multiplier;
8937                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
8938
8939                                                                                         if(player[i].aiupdatedelay<0){
8940                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
8941                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
8942                                                                                                         Normalise(&rotatetarget);
8943                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
8944                                                                                                         player[i].targetrotation*=360/6.28;
8945                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
8946                                                                                                         player[i].lookrotation=player[i].targetrotation;
8947                                                                                                         player[i].aiupdatedelay=.05;
8948
8949                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
8950                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
8951                                                                                                                 player[i].waypoint++;
8952                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
8953
8954                                                                                                         }
8955                                                                                                 }
8956
8957                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
8958                                                                                                 else player[i].forwardkeydown=0;
8959                                                                                                 player[i].leftkeydown=0;
8960                                                                                                 player[i].backkeydown=0;
8961                                                                                                 player[i].rightkeydown=0;
8962                                                                                                 player[i].crouchkeydown=0;
8963                                                                                                 player[i].attackkeydown=0;
8964                                                                                                 player[i].throwkeydown=0;
8965
8966                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
8967                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
8968                                                                                                         else{
8969                                                                                                                 XYZ leftpos,rightpos;
8970                                                                                                                 float leftdist,rightdist;
8971                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
8972                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
8973                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
8974                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
8975                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
8976                                                                                                                 else player[i].targetrotation-=90;
8977                                                                                                         }
8978                                                                                                 }
8979                                                                                         }
8980                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
8981                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
8982
8983
8984                                                                                         if(!editorenabled){
8985                                                                                                 if(player[i].howactive<typesleeping)
8986                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
8987                                                                                                                 for(j=0;j<numenvsounds;j++){
8988                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
8989                                                                                                                                 player[i].aitype=attacktypecutoff;
8990                                                                                                                         }
8991                                                                                                                 }
8992
8993                                                                                                                 if(player[i].howactive==typesleeping)
8994                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
8995                                                                                                                                 for(j=0;j<numenvsounds;j++){
8996                                                                                                                                         if(envsoundvol[j]>14)
8997                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
8998                                                                                                                                                         player[i].aitype=attacktypecutoff;
8999                                                                                                                                                 }
9000                                                                                                                                 }
9001
9002                                                                                                                                 if(player[i].aitype!=passivetype){
9003                                                                                                                                         if(player[i].howactive==typesleeping){
9004                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9005                                                                                                                                                 player[i].targetframe=0;
9006                                                                                                                                                 player[i].target=0;
9007                                                                                                                                         }
9008
9009                                                                                                                                         player[i].howactive=typeactive;
9010                                                                                                                                 }
9011                                                                                         }
9012
9013                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9014                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9015                                                                                                         player[i].aitype=attacktypecutoff;
9016                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9017                                                                                                         player[i].aitype=attacktypecutoff;
9018
9019                                                                                                 if(player[i].creature==wolftype){
9020                                                                                                         XYZ windsmell;
9021                                                                                                         float smelldistance;
9022                                                                                                         smelldistance=50;
9023                                                                                                         for(j=0;j<numplayers;j++){
9024                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9025                                                                                                                         if(j==0&&player[j].num_weapons>0){
9026                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9027                                                                                                                                 if(player[j].num_weapons==2)
9028                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9029                                                                                                                         }
9030                                                                                                                         if(j!=0){
9031                                                                                                                                 smelldistance=100;
9032                                                                                                                         }
9033                                                                                                                         windsmell=windvector;
9034                                                                                                                         Normalise(&windsmell);
9035                                                                                                                         windsmell=windsmell*2+player[j].coords;
9036                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9037                                                                                                                                 player[i].aitype=attacktypecutoff;
9038                                                                                                                 }
9039                                                                                                         }
9040                                                                                                 }
9041
9042                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9043                                                                                                         player[i].losupdatedelay=.2;
9044                                                                                                         for(j=0;j<numplayers;j++){
9045                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9046                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9047                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9048                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9049                                                                                                                                                 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)){
9050                                                                                                                                                         player[i].lastseentime-=.2;
9051                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9052                                                                                                                                                         else player[i].lastseentime-=.6;
9053                                                                                                                                                 }
9054                                                                                                                                                 if(player[i].lastseentime<=0){
9055                                                                                                                                                         player[i].aitype=searchtype;
9056                                                                                                                                                         player[i].lastchecktime=12;
9057                                                                                                                                                         player[i].lastseen=player[j].coords;
9058                                                                                                                                                         player[i].lastseentime=12;
9059                                                                                                                                                 }
9060                                                                                                                 }
9061                                                                                                         }
9062                                                                                                 }
9063                                                                                         }
9064                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9065                                                                                                 if(player[i].creature!=wolftype){
9066                                                                                                         player[i].stunned=.6;
9067                                                                                                         player[i].surprised=.6;
9068                                                                                                 }
9069                                                                                                 if(player[i].creature==wolftype){
9070                                                                                                         player[i].stunned=.47;
9071                                                                                                         player[i].surprised=.47;
9072                                                                                                 }
9073                                                                                                 numseen++;
9074                                                                                         }
9075                                                                                 }
9076
9077                                                                                 if(player[i].aitype==searchtype){
9078                                                                                         player[i].aiupdatedelay-=multiplier;
9079                                                                                         player[i].losupdatedelay-=multiplier;
9080                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9081                                                                                         player[i].lastchecktime-=multiplier;
9082
9083                                                                                         if(player[i].isRun()&&!player[i].onground){
9084                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9085                                                                                                         test2=player[i].coords+player[i].facing;
9086                                                                                                         test2.y+=5;
9087                                                                                                         test=player[i].coords+player[i].facing;
9088                                                                                                         test.y-=10;
9089                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9090                                                                                                         if(j==-1)j=checkcollide(test2,test);
9091                                                                                                         if(j==-1){
9092                                                                                                                 player[i].velocity=0;
9093                                                                                                                 player[i].targetanimation=player[i].getStop();
9094                                                                                                                 player[i].targetframe=0;
9095                                                                                                                 player[i].target=0;
9096                                                                                                                 player[i].targetrotation+=180;
9097                                                                                                                 player[i].stunned=.5;
9098                                                                                                                 //player[i].aitype=passivetype;
9099                                                                                                                 player[i].aitype=pathfindtype;
9100                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9101                                                                                                                 player[i].finalpathfindpoint=-1;
9102                                                                                                                 player[i].targetpathfindpoint=-1;
9103                                                                                                                 player[i].lastpathfindpoint=-1;
9104                                                                                                                 player[i].lastpathfindpoint2=-1;
9105                                                                                                                 player[i].lastpathfindpoint3=-1;
9106                                                                                                                 player[i].lastpathfindpoint4=-1;
9107                                                                                                         }
9108                                                                                                         else player[i].laststanding=j;
9109                                                                                                 }
9110                                                                                         }
9111                                                                                         if(player[i].aiupdatedelay<0){
9112                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9113                                                                                                 Normalise(&rotatetarget);
9114                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9115                                                                                                 player[i].targetrotation*=360/6.28;
9116                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9117                                                                                                 player[i].lookrotation=player[i].targetrotation;
9118                                                                                                 player[i].aiupdatedelay=.05;
9119                                                                                                 player[i].forwardkeydown=1;
9120
9121                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9122                                                                                                         player[i].forwardkeydown=0;
9123                                                                                                         player[i].aiupdatedelay=1;
9124                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9125                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9126                                                                                                         player[i].lastchecktime=3;
9127                                                                                                 }
9128
9129                                                                                                 player[i].leftkeydown=0;
9130                                                                                                 player[i].backkeydown=0;
9131                                                                                                 player[i].rightkeydown=0;
9132                                                                                                 player[i].crouchkeydown=0;
9133                                                                                                 player[i].attackkeydown=0;
9134                                                                                                 player[i].throwkeydown=0;
9135
9136                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9137                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9138                                                                                                         else{
9139                                                                                                                 XYZ leftpos,rightpos;
9140                                                                                                                 float leftdist,rightdist;
9141                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9142                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9143                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9144                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9145                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9146                                                                                                                 else player[i].targetrotation-=90;
9147                                                                                                         }
9148                                                                                                 }
9149                                                                                         }
9150                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9151                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9152
9153                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9154                                                                                                 for(j=0;j<numenvsounds;j++){
9155                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9156                                                                                                                 player[i].aitype=attacktypecutoff;
9157                                                                                                         }
9158                                                                                                 }
9159
9160                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9161                                                                                                         player[i].losupdatedelay=.2;
9162                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9163                                                                                                         {player[i].aitype=attacktypecutoff;
9164                                                                                                         player[i].lastseentime=1;}
9165                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9166                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9167                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9168                                                                                                                                 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)){
9169                                                                                                                                         player[i].aitype=attacktypecutoff;
9170                                                                                                                                         player[i].lastseentime=1;
9171                                                                                                                                 }
9172                                                                                                 }
9173                                                                                                 if(player[i].lastseentime<0){
9174                                                                                                         //player[i].aitype=passivetype;
9175                                                                                                         numescaped++;
9176                                                                                                         player[i].aitype=pathfindtype;
9177                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9178                                                                                                         player[i].finalpathfindpoint=-1;
9179                                                                                                         player[i].targetpathfindpoint=-1;
9180                                                                                                         player[i].lastpathfindpoint=-1;
9181                                                                                                         player[i].lastpathfindpoint2=-1;
9182                                                                                                         player[i].lastpathfindpoint3=-1;
9183                                                                                                         player[i].lastpathfindpoint4=-1;
9184                                                                                                 }
9185                                                                                 }
9186
9187                                                                                 if(player[i].aitype!=gethelptype){
9188                                                                                         player[i].runninghowlong=0;
9189                                                                                 }
9190
9191                                                                                 if(player[i].aitype==gethelptype){
9192                                                                                         player[i].runninghowlong+=multiplier;
9193                                                                                         player[i].aiupdatedelay-=multiplier;
9194
9195                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9196                                                                                                 player[i].aiupdatedelay=.2;
9197
9198                                                                                                 int closest;
9199                                                                                                 float closestdist;
9200                                                                                                 closest=-1;
9201                                                                                                 closestdist=-1;
9202                                                                                                 float distance;
9203
9204                                                                                                 if(!player[i].ally){
9205                                                                                                         for(j=0;j<numplayers;j++){
9206                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9207                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9208                                                                                                                         if(closestdist==-1||distance<closestdist){
9209                                                                                                                                 closestdist=distance;
9210                                                                                                                                 closest=j;
9211                                                                                                                         }
9212                                                                                                                         closest=j;
9213                                                                                                                 }
9214                                                                                                         }
9215                                                                                                         if(closest!=-1)player[i].ally=closest;
9216                                                                                                         else player[i].ally=0;
9217                                                                                                         player[i].lastseen=player[0].coords;
9218                                                                                                         player[i].lastseentime=12;
9219                                                                                                 }
9220
9221
9222                                                                                                 player[i].lastchecktime=12;
9223                                                                                                 //player[i].lastseentime-=.5;
9224
9225                                                                                                 facing=player[i].coords;
9226                                                                                                 flatfacing=player[player[i].ally].coords;
9227                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9228                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9229                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9230                                                                                                         player[i].lastseentime-=.1;
9231
9232                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9233                                                                                                         player[i].aitype=searchtype;
9234                                                                                                         player[i].lastseentime=12;
9235                                                                                                 }
9236
9237                                                                                                 if(player[i].ally>0){
9238                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9239                                                                                                         Normalise(&rotatetarget);
9240                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9241                                                                                                         player[i].targetrotation*=360/6.28;
9242                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9243                                                                                                         player[i].lookrotation=player[i].targetrotation;
9244                                                                                                         player[i].aiupdatedelay=.05;
9245                                                                                                         player[i].forwardkeydown=1;
9246
9247                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9248                                                                                                                 player[i].aitype=searchtype;
9249                                                                                                                 player[i].lastseentime=12;
9250                                                                                                                 player[player[i].ally].aitype=searchtype;
9251                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9252                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9253                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9254                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9255                                                                                                                 }
9256                                                                                                         }
9257
9258                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9259                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9260                                                                                                                 else{
9261                                                                                                                         XYZ leftpos,rightpos;
9262                                                                                                                         float leftdist,rightdist;
9263                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9264                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9265                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9266                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9267                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9268                                                                                                                         else player[i].targetrotation-=90;
9269                                                                                                                 }
9270                                                                                                         }
9271                                                                                                 }
9272
9273                                                                                                 player[i].leftkeydown=0;
9274                                                                                                 player[i].backkeydown=0;
9275                                                                                                 player[i].rightkeydown=0;
9276                                                                                                 player[i].crouchkeydown=0;
9277                                                                                                 player[i].attackkeydown=0;
9278                                                                                         }
9279                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9280                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9281                                                                                 }
9282
9283                                                                                 if(player[i].aitype==getweapontype){
9284                                                                                         player[i].aiupdatedelay-=multiplier;
9285                                                                                         player[i].lastchecktime-=multiplier;
9286
9287                                                                                         if(player[i].aiupdatedelay<0){
9288                                                                                                 player[i].aiupdatedelay=.2;
9289
9290                                                                                                 int closest;
9291                                                                                                 float closestdist;
9292                                                                                                 closest=-1;
9293                                                                                                 closestdist=-1;
9294                                                                                                 float distance;
9295
9296                                                                                                 if(player[i].ally<0){
9297                                                                                                         for(j=0;j<weapons.numweapons;j++){
9298                                                                                                                 if(weapons.owner[j]==-1){
9299                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9300                                                                                                                         if(closestdist==-1||distance<closestdist){
9301                                                                                                                                 closestdist=distance;
9302                                                                                                                                 closest=j;
9303                                                                                                                         }
9304                                                                                                                         closest=j;
9305                                                                                                                 }
9306                                                                                                         }
9307                                                                                                         if(closest!=-1)player[i].ally=closest;
9308                                                                                                         else player[i].ally=-1;
9309                                                                                                 }
9310
9311                                                                                                 player[i].lastseentime=12;
9312
9313                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9314                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9315                                                                                                                 player[i].aitype=attacktypecutoff;
9316                                                                                                                 player[i].lastseentime=1;
9317                                                                                                         }
9318                                                                                                         if(!player[0].dead)
9319                                                                                                                 if(player[i].ally>=0){
9320                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9321                                                                                                                                 player[i].aitype=attacktypecutoff;
9322                                                                                                                                 player[i].lastseentime=1;
9323                                                                                                                         }
9324                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9325                                                                                                                         Normalise(&rotatetarget);
9326                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9327                                                                                                                         player[i].targetrotation*=360/6.28;
9328                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9329                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9330                                                                                                                         player[i].aiupdatedelay=.05;
9331                                                                                                                         player[i].forwardkeydown=1;
9332
9333
9334                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9335                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9336                                                                                                                                 else{
9337                                                                                                                                         XYZ leftpos,rightpos;
9338                                                                                                                                         float leftdist,rightdist;
9339                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9340                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9341                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9342                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9343                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9344                                                                                                                                         else player[i].targetrotation-=90;
9345                                                                                                                                 }
9346                                                                                                                         }
9347                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9348                                                                                                                         if(abs(Random()%6)){
9349                                                                                                                         player[i].crouchkeydown=1;
9350                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9351                                                                                                                         if(player[i].isRun()){
9352                                                                                                                         player[i].targetframe=0;
9353                                                                                                                         player[i].target=0;
9354                                                                                                                         player[i].targetanimation=sneakanim;
9355                                                                                                                         }
9356                                                                                                                         }
9357                                                                                                                         else player[i].forwardkeydown=0;
9358                                                                                                                         }
9359                                                                                                                         else player[i].crouchkeydown=0;
9360                                                                                                                         }
9361                                                                                                                         else player[i].crouchkeydown=0;*/
9362                                                                                                                 }
9363
9364                                                                                                                 player[i].leftkeydown=0;
9365                                                                                                                 player[i].backkeydown=0;
9366                                                                                                                 player[i].rightkeydown=0;
9367                                                                                                                 player[i].attackkeydown=0;
9368                                                                                                                 player[i].throwkeydown=1;
9369                                                                                                                 player[i].crouchkeydown=0;
9370                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9371                                                                                                                 player[i].drawkeydown=0;
9372                                                                                         }
9373                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9374                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9375                                                                                 }
9376
9377                                                                                 if(player[i].aitype==attacktypecutoff){
9378                                                                                         player[i].aiupdatedelay-=multiplier;
9379                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9380                                                                                                 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)){
9381                                                                                                         player[i].attackkeydown=0;
9382                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9383                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9384                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9385                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9386                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9387                                                                                                                                 else player[i].targetanimation=rollanim;
9388                                                                                                                                 player[i].target=0;
9389                                                                                                                                 player[i].targetframe=0;
9390                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9391                                                                                                                                 player[i].wentforweapon=0;
9392                                                                                                                         }
9393                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9394                                                                                                                                 player[i].targetanimation=flipanim;
9395                                                                                                                                 player[i].target=0;
9396                                                                                                                                 player[i].targetframe=0;
9397                                                                                                                         }
9398                                                                                                                 }
9399                                                                                                         }
9400                                                                                                         player[i].forwardkeydown=0;
9401                                                                                                         player[i].aiupdatedelay=.02;
9402                                                                                                 }
9403                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9404                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9405                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9406                                                                                                 }
9407                                                                                                 if(player[i].wentforweapon<3)
9408                                                                                                         for(j=0;j<weapons.numweapons;j++){
9409                                                                                                                 if(player[i].creature!=wolftype)
9410                                                                                                                         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){
9411                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9412                                                                                                                                         player[i].wentforweapon++;
9413                                                                                                                                         player[i].lastchecktime=6;
9414                                                                                                                                         player[i].aitype=getweapontype;
9415                                                                                                                                         player[i].ally=-1;
9416                                                                                                                                 }
9417                                                                                                                         }
9418                                                                                                         }
9419                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9420                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9421                                                                                                                         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)))){
9422                                                                                                                                 player[i].crouchkeydown=1;
9423                                                                                                                         }
9424                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9425                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9426                                                                                                                                         test2=player[i].coords+player[i].facing;
9427                                                                                                                                         test2.y+=5;
9428                                                                                                                                         test=player[i].coords+player[i].facing;
9429                                                                                                                                         test.y-=10;
9430                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9431                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9432                                                                                                                                         if(j==-1){
9433                                                                                                                                                 player[i].velocity=0;
9434                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9435                                                                                                                                                 player[i].targetframe=0;
9436                                                                                                                                                 player[i].target=0;
9437                                                                                                                                                 player[i].targetrotation+=180;
9438                                                                                                                                                 player[i].stunned=.5;
9439                                                                                                                                                 //player[i].aitype=passivetype;
9440                                                                                                                                                 player[i].aitype=pathfindtype;
9441                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9442                                                                                                                                                 player[i].finalpathfindpoint=-1;
9443                                                                                                                                                 player[i].targetpathfindpoint=-1;
9444                                                                                                                                                 player[i].lastpathfindpoint=-1;
9445                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9446                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9447                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9448                                                                                                                                         }
9449                                                                                                                                         else player[i].laststanding=j;
9450                                                                                                                                 }
9451                                                                                                                         }
9452                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9453                                                                                                                                 player[i].aitype=pathfindtype;
9454                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9455                                                                                                                                 player[i].finalpathfindpoint=-1;
9456                                                                                                                                 player[i].targetpathfindpoint=-1;
9457                                                                                                                                 player[i].lastpathfindpoint=-1;
9458                                                                                                                                 player[i].lastpathfindpoint2=-1;
9459                                                                                                                                 player[i].lastpathfindpoint3=-1;
9460                                                                                                                                 player[i].lastpathfindpoint4=-1;
9461                                                                                                                         }
9462                                                                                                                         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){
9463                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9464                                                                                                                                 else player[i].drawkeydown=0;
9465                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9466                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9467                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9468                                                                                                                                         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;
9469                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9470                                                                                                                                 Normalise(&rotatetarget);
9471                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9472                                                                                                                                 player[i].targetrotation*=360/6.28;
9473                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9474                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9475                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9476
9477                                                                                                                                 oldkey=player[i].forwardkeydown;
9478                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9479                                                                                                                                 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;
9480                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9481                                                                                                                                 else player[i].forwardkeydown=0;
9482                                                                                                                                 if(player[0].dead){
9483                                                                                                                                         player[i].forwardkeydown=0;
9484                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9485                                                                                                                                         if(Random()%100==0){
9486                                                                                                                                                 player[i].aitype=pathfindtype;
9487                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9488                                                                                                                                                 player[i].finalpathfindpoint=-1;
9489                                                                                                                                                 player[i].targetpathfindpoint=-1;
9490                                                                                                                                                 player[i].lastpathfindpoint=-1;
9491                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9492                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9493                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9494                                                                                                                                         }
9495                                                                                                                                 }
9496                                                                                                                                 player[i].leftkeydown=0;
9497                                                                                                                                 player[i].backkeydown=0;
9498                                                                                                                                 player[i].rightkeydown=0;
9499                                                                                                                                 player[i].crouchkeydown=0;
9500                                                                                                                                 player[i].throwkeydown=0;
9501
9502                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9503                                                                                                                                 /*for(j=0;j<numplayers;j++){
9504                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9505                                                                                                                                 player[i].crouchkeydown=1;
9506                                                                                                                                 }
9507                                                                                                                                 }*/
9508                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9509                                                                                                                                 else player[i].attackkeydown=0;
9510                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9511                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9512                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9513                                                                                                                                 player[i].attackkeydown=0;
9514                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9515                                                                                                                                 player[i].forwardkeydown=0;
9516                                                                                                                                 player[i].aiupdatedelay=.02;
9517                                                                                                                                 }*/
9518
9519                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9520                                                                                                                                         target=-2;
9521                                                                                                                                         for(j=0;j<numplayers;j++){
9522                                                                                                                                                 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)){
9523                                                                                                                                                         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))))){
9524                                                                                                                                                                 if(target>=0)target=-1;
9525                                                                                                                                                                 else target=j;
9526                                                                                                                                                         }
9527                                                                                                                                                 }
9528                                                                                                                                         }
9529                                                                                                                                         if(target>=0)player[target].Reverse();
9530                                                                                                                                 }
9531
9532                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9533                                                                                                                                 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;
9534                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9535                                                                                                                                         player[0].jumpkeydown=0;
9536                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9537                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9538                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9539
9540                                                                                                                                 if(tutoriallevel==1){
9541                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9542                                                                                                                                 }
9543
9544
9545                                                                                                                                 facing=player[i].coords;
9546                                                                                                                                 flatfacing=player[0].coords;
9547                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9548                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9549                                                                                                                                 if(player[i].occluded>=2)
9550                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9551                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9552                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9553                                                                                                                                                         player[i].aitype=searchtype;
9554                                                                                                                                                         player[i].lastchecktime=12;
9555                                                                                                                                                         player[i].lastseen=player[0].coords;
9556                                                                                                                                                         player[i].lastseentime=12;
9557                                                                                                                                                 }
9558                                                                                                                                         }
9559                                                                                                                                         else player[i].lastseentime=1;
9560                                                                                                                         }
9561                                                                                 }
9562                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9563                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9564                                                                                                 test=player[0].coords;
9565                                                                                                 test.y-=40;
9566                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9567                                                                                         }
9568                                                                                 }
9569                                                                                 // NOTE: Ask about logic of this call : NOTE
9570                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9571                                                                                         player[i].stunned>0 ||
9572                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9573                                                                                 {
9574                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9575                                                                                         player[i].targetrotation=player[i].rotation;
9576                                                                                         player[i].forwardkeydown=0;
9577                                                                                         player[i].leftkeydown=0;
9578                                                                                         player[i].backkeydown=0;
9579                                                                                         player[i].rightkeydown=0;
9580                                                                                         player[i].jumpkeydown=0;
9581                                                                                         player[i].attackkeydown=0;
9582                                                                                         player[i].crouchkeydown=0;
9583                                                                                         player[i].throwkeydown=0;
9584                                                                                 }
9585
9586
9587                                                                                 facing=0;
9588                                                                                 facing.z=-1;
9589
9590                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9591                                                                                 facing=flatfacing;
9592
9593                                                                                 if(player[i].aitype==attacktypecutoff){
9594                                                                                         rotatetarget=player[0].coords-player[i].coords;
9595                                                                                         Normalise(&rotatetarget);
9596                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9597                                                                                         player[i].targetheadrotation*=360/6.28;
9598                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9599
9600                                                                                         player[i].targetheadrotation*=-1;
9601                                                                                         player[i].targetheadrotation+=180;
9602                                                                                         //player[i].targetheadrotation2=0;
9603                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9604                                                                                 }
9605                                                                                 else if(player[i].howactive>=typesleeping){
9606                                                                                         player[i].targetheadrotation=player[i].targetrotation;
9607                                                                                         player[i].targetheadrotation2=0;
9608                                                                                 }
9609                                                                                 else {
9610                                                                                         if(player[i].interestdelay<=0){
9611                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
9612                                                                                                 player[i].headtarget=player[i].coords;
9613                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
9614                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
9615                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
9616                                                                                                 player[i].headtarget+=player[i].facing*1.5;
9617                                                                                         }
9618                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
9619                                                                                         Normalise(&rotatetarget);
9620                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9621                                                                                         player[i].targetheadrotation*=360/6.28;
9622                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9623
9624                                                                                         player[i].targetheadrotation*=-1;
9625                                                                                         player[i].targetheadrotation+=180;
9626                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9627                                                                                 }
9628                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
9629                                                                         }
9630                                                                         if(animation[player[i].targetanimation].attack==reversed){
9631                                                                                 //player[i].targetrotation=player[i].rotation;
9632                                                                                 player[i].forwardkeydown=0;
9633                                                                                 player[i].leftkeydown=0;
9634                                                                                 player[i].backkeydown=0;
9635                                                                                 player[i].rightkeydown=0;
9636                                                                                 player[i].jumpkeydown=0;
9637                                                                                 player[i].attackkeydown=0;
9638                                                                                 //player[i].crouchkeydown=0;
9639                                                                                 player[i].throwkeydown=0;
9640                                                                         }
9641
9642                                                                         if(indialogue!=-1){
9643                                                                                 player[i].forwardkeydown=0;
9644                                                                                 player[i].leftkeydown=0;
9645                                                                                 player[i].backkeydown=0;
9646                                                                                 player[i].rightkeydown=0;
9647                                                                                 player[i].jumpkeydown=0;
9648                                                                                 player[i].crouchkeydown=0;
9649                                                                                 player[i].drawkeydown=0;
9650                                                                                 player[i].throwkeydown=0;
9651                                                                         }
9652
9653                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
9654                                                                         if(player[i].collided>1)player[i].collided=1;
9655                                                                         player[i].collided-=multiplier*4;
9656                                                                         player[i].whichdirectiondelay-=multiplier;
9657                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
9658                                                                                 player[i].avoidcollided=-.3;
9659                                                                                 player[i].whichdirection=abs(Random()%2);
9660                                                                                 player[i].whichdirectiondelay=.4;
9661                                                                         }
9662                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
9663                                                                         player[i].avoidcollided-=multiplier/4;
9664                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
9665                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
9666                                                                         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;
9667
9668                                                                         if(!player[i].throwkeydown){
9669                                                                                 player[i].throwtogglekeydown=0;
9670                                                                         }
9671                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
9672                                                                                 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)){
9673                                                                                         for(j=0;j<weapons.numweapons;j++){
9674                                                                                                 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)
9675                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
9676                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
9677                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
9678                                                                                                                                 player[i].throwtogglekeydown=1;
9679                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
9680                                                                                                                                 player[i].target=0;
9681                                                                                                                                 player[i].targetframe=0;
9682                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
9683                                                                                                                                 Normalise(&rotatetarget);
9684                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9685                                                                                                                                 player[i].targetrotation*=360/6.28;
9686                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9687                                                                                                                                 player[i].hasvictim=0;
9688                                                                                                                         }
9689                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9690                                                                                                                                 player[i].throwtogglekeydown=1;
9691                                                                                                                                 player[i].hasvictim=0;
9692
9693                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
9694                                                                                                                                 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))
9695                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
9696                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
9697                                                                                                                                                         float gLoc[3];
9698                                                                                                                                                         float vel[3];
9699                                                                                                                                                         gLoc[0]=player[i].coords.x;
9700                                                                                                                                                         gLoc[1]=player[i].coords.y;
9701                                                                                                                                                         gLoc[2]=player[i].coords.z;
9702                                                                                                                                                         vel[0]=player[i].velocity.x;
9703                                                                                                                                                         vel[1]=player[i].velocity.y;
9704                                                                                                                                                         vel[2]=player[i].velocity.z;
9705                                                                                                                                                         if(weapons.type[j]!=staff){
9706                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9707                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9708                                                                                                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
9709                                                                                                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
9710                                                                                                                                                         }
9711
9712                                                                                                                                                         player[i].weaponactive=0;
9713                                                                                                                                                         weapons.owner[j]=player[i].id;
9714                                                                                                                                                         if(player[i].num_weapons>0){
9715                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9716                                                                                                                                                         }
9717                                                                                                                                                         player[i].num_weapons++;
9718                                                                                                                                                         player[i].weaponids[0]=j;
9719                                                                                                                                                 }
9720                                                                                                                                         }
9721                                                                                                                                         //}
9722                                                                                                                         }
9723                                                                                                                 }
9724                                                                                                                 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){
9725                                                                                                                         if(!player[i].isFlip()){
9726                                                                                                                                 player[i].throwtogglekeydown=1;
9727                                                                                                                                 player[i].targetanimation=removeknifeanim;
9728                                                                                                                                 player[i].target=0;
9729                                                                                                                                 player[i].targetframe=0;
9730                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
9731                                                                                                                                 Normalise(&rotatetarget);
9732                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9733                                                                                                                                 player[i].targetrotation*=360/6.28;
9734                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9735                                                                                                                         }
9736                                                                                                                         if(player[i].isFlip()){
9737                                                                                                                                 player[i].throwtogglekeydown=1;
9738                                                                                                                                 player[i].hasvictim=0;
9739
9740                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
9741                                                                                                                                         if(player[i].weaponactive==-1)
9742                                                                                                                                                 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))
9743                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
9744                                                                                                                                                                 float gLoc[3];
9745                                                                                                                                                                 float vel[3];
9746                                                                                                                                                                 gLoc[0]=player[i].coords.x;
9747                                                                                                                                                                 gLoc[1]=player[i].coords.y;
9748                                                                                                                                                                 gLoc[2]=player[i].coords.z;
9749                                                                                                                                                                 vel[0]=player[i].velocity.x;
9750                                                                                                                                                                 vel[1]=player[i].velocity.y;
9751                                                                                                                                                                 vel[2]=player[i].velocity.z;
9752                                                                                                                                                                 if(weapons.type[k]!=staff){
9753                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9754                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9755                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
9756                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
9757                                                                                                                                                                 }
9758
9759                                                                                                                                                                 player[i].weaponactive=0;
9760                                                                                                                                                                 weapons.owner[k]=player[i].id;
9761                                                                                                                                                                 if(player[i].num_weapons>0){
9762                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9763                                                                                                                                                                 }
9764                                                                                                                                                                 player[i].num_weapons++;
9765                                                                                                                                                                 player[i].weaponids[0]=k;
9766                                                                                                                                                         }
9767                                                                                                                                 }
9768                                                                                                                         }
9769                                                                                                                 }
9770                                                                                                         }
9771                                                                                         }
9772                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9773                                                                                                 if(numplayers>1)
9774                                                                                                         for(j=0;j<numplayers;j++){
9775                                                                                                                 if(player[i].weaponactive==-1)
9776                                                                                                                         if(j!=i)
9777                                                                                                                                 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)){
9778                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
9779                                                                                                                                                 player[i].throwtogglekeydown=1;
9780                                                                                                                                                 player[i].victim=&player[j];
9781                                                                                                                                                 player[i].hasvictim=1;
9782                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
9783                                                                                                                                                 player[i].target=0;
9784                                                                                                                                                 player[i].targetframe=0;
9785                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
9786                                                                                                                                                 Normalise(&rotatetarget);
9787                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9788                                                                                                                                                 player[i].targetrotation*=360/6.28;
9789                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9790                                                                                                                                         }
9791                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9792                                                                                                                                                 player[i].throwtogglekeydown=1;
9793                                                                                                                                                 player[i].victim=&player[j];
9794                                                                                                                                                 player[i].hasvictim=1;
9795                                                                                                                                                 int k = player[j].weaponids[0];
9796                                                                                                                                                 if(player[i].hasvictim){
9797                                                                                                                                                         float gLoc[3];
9798                                                                                                                                                         float vel[3];
9799                                                                                                                                                         gLoc[0]=player[i].coords.x;
9800                                                                                                                                                         gLoc[1]=player[i].coords.y;
9801                                                                                                                                                         gLoc[2]=player[i].coords.z;
9802                                                                                                                                                         vel[0]=player[i].velocity.x;
9803                                                                                                                                                         vel[1]=player[i].velocity.y;
9804                                                                                                                                                         vel[2]=player[i].velocity.z;
9805                                                                                                                                                         bool fleshstuck;
9806                                                                                                                                                         fleshstuck=0;
9807                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
9808                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
9809                                                                                                                                                                         fleshstuck=1;
9810                                                                                                                                                                 }
9811                                                                                                                                                         }
9812                                                                                                                                                         if(!fleshstuck){
9813                                                                                                                                                                 if(weapons.type[k]!=staff){
9814                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9815                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9816                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
9817                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
9818                                                                                                                                                                 }
9819                                                                                                                                                         }
9820                                                                                                                                                         if(fleshstuck){
9821                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
9822                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
9823                                                                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
9824                                                                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
9825                                                                                                                                                         }
9826
9827                                                                                                                                                         player[i].weaponactive=0;
9828                                                                                                                                                         if(weapons.owner[k]!=-1){
9829                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
9830                                                                                                                                                                 else player[i].victim->num_weapons=1;
9831
9832                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
9833                                                                                                                                                                 player[i].victim->skeleton.free=1;
9834                                                                                                                                                                 player[i].victim->skeleton.broken=0;
9835
9836                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
9837                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
9838                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
9839                                                                                                                                                                 }
9840
9841                                                                                                                                                                 XYZ relative;
9842                                                                                                                                                                 relative=0;
9843                                                                                                                                                                 relative.y=10;
9844                                                                                                                                                                 Normalise(&relative);
9845                                                                                                                                                                 XYZ footvel,footpoint;
9846                                                                                                                                                                 footvel=0;
9847                                                                                                                                                                 footpoint=weapons.position[k];
9848                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
9849                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
9850                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
9851                                                                                                                                                                                 weapons.bloody[k]=2;
9852                                                                                                                                                                                 weapons.blooddrip[k]=5;
9853                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
9854                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
9855                                                                                                                                                                                 player[i].victim->DoDamage(2000);
9856                                                                                                                                                                         }
9857                                                                                                                                                                 }
9858                                                                                                                                                                 if(player[i].victim->num_weapons>0){
9859                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
9860                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
9861                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
9862                                                                                                                                                                 }
9863
9864                                                                                                                                                                 player[i].victim->weaponactive=-1;
9865
9866                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
9867                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
9868                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
9869                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
9870                                                                                                                                                         }
9871                                                                                                                                                         weapons.owner[k]=i;
9872                                                                                                                                                         if(player[i].num_weapons>0){
9873                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9874                                                                                                                                                         }
9875                                                                                                                                                         player[i].num_weapons++;
9876                                                                                                                                                         player[i].weaponids[0]=k;
9877                                                                                                                                                 }
9878                                                                                                                                         }
9879                                                                                                                                 }
9880                                                                                                         }
9881                                                                                         }
9882                                                                                 }
9883                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
9884                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
9885                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
9886                                                                                                         if(numplayers>1)
9887                                                                                                                 for(j=0;j<numplayers;j++){
9888                                                                                                                         if(i!=j)
9889                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
9890                                                                                                                                         if(hostile)
9891                                                                                                                                                 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)){
9892                                                                                                                                                         if(!player[i].isFlip()){
9893                                                                                                                                                                 player[i].throwtogglekeydown=1;
9894                                                                                                                                                                 player[i].victim=&player[j];
9895                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
9896                                                                                                                                                                 player[i].target=0;
9897                                                                                                                                                                 player[i].targetframe=0;
9898                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
9899                                                                                                                                                                 Normalise(&rotatetarget);
9900                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9901                                                                                                                                                                 player[i].targetrotation*=360/6.28;
9902                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9903
9904                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
9905                                                                                                                                                         }
9906                                                                                                                                                         if(player[i].isFlip()){
9907                                                                                                                                                                 if(player[i].weaponactive!=-1){
9908                                                                                                                                                                         player[i].throwtogglekeydown=1;
9909                                                                                                                                                                         player[i].victim=&player[j];
9910                                                                                                                                                                         XYZ aim;
9911                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
9912                                                                                                                                                                         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);
9913                                                                                                                                                                         Normalise(&aim);
9914
9915                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
9916
9917                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
9918                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
9919                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
9920                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
9921                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
9922                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
9923                                                                                                                                                                         player[i].num_weapons--;
9924                                                                                                                                                                         if(player[i].num_weapons){
9925                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
9926                                                                                                                                                                         }
9927                                                                                                                                                                         player[i].weaponactive=-1;
9928                                                                                                                                                                 }
9929                                                                                                                                                         }
9930                                                                                                                                                 }
9931                                                                                                                 }
9932                                                                                         }
9933                                                                                 }
9934                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
9935                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
9936                                                                                         {
9937                                                                                                 player[i].throwtogglekeydown=1;
9938                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
9939                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
9940                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
9941                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
9942                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
9943                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
9944                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
9945                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
9946                                                                                                 player[i].num_weapons--;
9947                                                                                                 if(player[i].num_weapons){
9948                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
9949                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
9950                                                                                                 }
9951
9952                                                                                                 player[i].weaponactive=-1;
9953                                                                                                 for(j=0;j<numplayers;j++){
9954                                                                                                         player[j].wentforweapon=0;
9955                                                                                                 }
9956                                                                                         }
9957                                                                                 }
9958
9959                                                                         }
9960
9961                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
9962                                                                                 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)){
9963                                                                                         //Setenvironment(1-environment);
9964                                                                                         bool isgood;
9965                                                                                         isgood=1;
9966                                                                                         if(player[i].weaponactive!=-1){
9967                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
9968                                                                                         }
9969                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
9970                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
9971                                                                                                         player[i].targetanimation=drawrightanim;
9972                                                                                                         player[i].targetframe=0;
9973                                                                                                         player[i].target=0;
9974                                                                                                         player[i].drawtogglekeydown=1;
9975                                                                                                 }
9976                                                                                                 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){
9977                                                                                                         player[i].targetanimation=drawleftanim;
9978                                                                                                         player[i].targetframe=0;
9979                                                                                                         player[i].target=0;
9980                                                                                                         player[i].drawtogglekeydown=1;
9981                                                                                                 }
9982                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
9983                                                                                                         player[i].targetanimation=crouchdrawrightanim;
9984                                                                                                         player[i].targetframe=0;
9985                                                                                                         player[i].target=0;
9986                                                                                                         player[i].drawtogglekeydown=1;
9987                                                                                                 }
9988                                                                                         }
9989                                                                                 }
9990                                                                                 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){
9991                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
9992                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
9993                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
9994                                                                                                 player[i].targetframe=0;
9995                                                                                                 player[i].target=0;
9996                                                                                                 player[i].hasvictim=0;
9997                                                                                                 //player[i].attacktogglekeydown=1;
9998                                                                                         }
9999                                                                                 }
10000
10001                                                                                 if(!player[i].drawkeydown){
10002                                                                                         player[i].drawtogglekeydown=0;
10003                                                                                 }
10004
10005                                                                                 if(i==0){
10006                                                                                         absflatfacing=0;
10007                                                                                         absflatfacing.z=-1;
10008
10009                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10010                                                                                 }
10011                                                                                 else absflatfacing=flatfacing;
10012
10013                                                                                 if(indialogue!=-1){
10014                                                                                         player[i].forwardkeydown=0;
10015                                                                                         player[i].leftkeydown=0;
10016                                                                                         player[i].backkeydown=0;
10017                                                                                         player[i].rightkeydown=0;
10018                                                                                         player[i].jumpkeydown=0;
10019                                                                                         player[i].crouchkeydown=0;
10020                                                                                         player[i].drawkeydown=0;
10021                                                                                         player[i].throwkeydown=0;
10022                                                                                 }
10023                                                                                 movekey=0;
10024                                                                                 //Do controls
10025                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10026                                                                                         if(!player[i].forwardkeydown){
10027                                                                                                 player[i].forwardstogglekeydown=0;
10028                                                                                         }
10029                                                                                         if(player[i].crouchkeydown){
10030                                                                                                 //Crouch
10031                                                                                                 target=-2;
10032                                                                                                 if(i==0){
10033                                                                                                         player[i].superruntoggle=1;
10034                                                                                                         if(numplayers>1)
10035                                                                                                                 for(j=0;j<numplayers;j++){
10036                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10037                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10038                                                                                                                                         player[i].superruntoggle=0;
10039                                                                                                                                 }
10040                                                                                                                         }
10041                                                                                                                 }
10042                                                                                                 }
10043
10044                                                                                                 if(numplayers>1)
10045                                                                                                         for(j=0;j<numplayers;j++){
10046                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10047                                                                                                                         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))){
10048                                                                                                                                 if(target>=0)target=-1;
10049                                                                                                                                 else target=j;
10050                                                                                                                         }
10051                                                                                                                 }
10052                                                                                                         }
10053                                                                                                         if(target>=0)player[target].Reverse();
10054                                                                                                         player[i].lowreversaldelay=.5;
10055
10056                                                                                                         if(player[i].isIdle()){
10057                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10058                                                                                                                 player[i].target=0;
10059                                                                                                                 player[i].targetframe=0;
10060                                                                                                                 player[i].transspeed=10;
10061                                                                                                         }
10062                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10063                                                                                                                 player[i].targetanimation=rollanim;
10064                                                                                                                 player[i].target=0;
10065                                                                                                                 player[i].targetframe=0;
10066                                                                                                                 player[i].transspeed=20;
10067                                                                                                         }
10068                                                                                         }
10069                                                                                         if(!player[i].crouchkeydown){
10070                                                                                                 //Uncrouch
10071                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10072                                                                                                 target=-2;
10073                                                                                                 if(player[i].isCrouch()){
10074                                                                                                         if(numplayers>1)
10075                                                                                                                 for(j=0;j<numplayers;j++){
10076                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10077                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10078                                                                                                                                         if(target>=0)target=-1;
10079                                                                                                                                         else target=j;
10080                                                                                                                                 }
10081                                                                                                                         }
10082                                                                                                                 }
10083                                                                                                                 if(target>=0)player[target].Reverse();
10084                                                                                                                 player[i].highreversaldelay=.5;
10085
10086                                                                                                                 if(player[i].isCrouch()){
10087                                                                                                                         if(!player[i].wasCrouch()){
10088                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10089                                                                                                                                 player[i].currentframe=0;
10090                                                                                                                         }
10091                                                                                                                         player[i].target=0;
10092                                                                                                                         player[i].targetanimation=player[i].getIdle();
10093                                                                                                                         player[i].targetframe=0;
10094                                                                                                                         player[i].transspeed=10;
10095                                                                                                                 }
10096                                                                                                 }
10097                                                                                                 if(player[i].targetanimation==sneakanim){
10098                                                                                                         player[i].targetanimation=player[i].getIdle();
10099                                                                                                         player[i].target=0;
10100                                                                                                         player[i].targetframe=0;
10101                                                                                                         player[i].transspeed=10;
10102                                                                                                 }
10103                                                                                         }
10104                                                                                         if(player[i].forwardkeydown){
10105                                                                                                 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)){
10106                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10107                                                                                                         else player[i].targetanimation=player[i].getRun();
10108                                                                                                         player[i].target=0;
10109                                                                                                         player[i].targetframe=0;
10110                                                                                                 }
10111                                                                                                 if(player[i].isCrouch()){
10112                                                                                                         player[i].targetanimation=sneakanim;
10113                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10114                                                                                                         player[i].targetframe=0;
10115                                                                                                 }
10116                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10117                                                                                                         player[i].targetanimation=climbanim;
10118                                                                                                         player[i].target=0;
10119                                                                                                         player[i].targetframe=1;
10120                                                                                                         player[i].jumpclimb=1;
10121                                                                                                 }
10122                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10123                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10124                                                                                                 }
10125                                                                                                 player[i].forwardstogglekeydown=1;
10126                                                                                                 movekey=1;
10127                                                                                         }
10128                                                                                         if (player[i].rightkeydown){
10129                                                                                                 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)){
10130                                                                                                         player[i].targetanimation=player[i].getRun();
10131                                                                                                         player[i].target=0;
10132                                                                                                         player[i].targetframe=0;
10133                                                                                                 }
10134                                                                                                 if(player[i].isCrouch()){
10135                                                                                                         player[i].targetanimation=sneakanim;
10136                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10137                                                                                                         player[i].targetframe=0;
10138                                                                                                 }
10139                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10140                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10141                                                                                                 }
10142                                                                                                 player[i].targetrotation-=90;
10143                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10144                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10145                                                                                                 movekey=1;
10146                                                                                         }
10147                                                                                         if ( player[i].leftkeydown){
10148                                                                                                 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)){
10149                                                                                                         player[i].targetanimation=player[i].getRun();
10150                                                                                                         player[i].target=0;
10151                                                                                                         player[i].targetframe=0;
10152                                                                                                 }
10153                                                                                                 if(player[i].isCrouch()){
10154                                                                                                         player[i].targetanimation=sneakanim;
10155                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10156                                                                                                         player[i].targetframe=0;
10157                                                                                                 }
10158                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10159                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10160                                                                                                 }
10161                                                                                                 player[i].targetrotation+=90;
10162                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10163                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10164                                                                                                 movekey=1;
10165                                                                                         }
10166                                                                                         if(player[i].backkeydown){
10167                                                                                                 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)){
10168                                                                                                         player[i].targetanimation=player[i].getRun();
10169                                                                                                         player[i].target=0;
10170                                                                                                         player[i].targetframe=0;
10171                                                                                                 }
10172                                                                                                 if(player[i].isCrouch()){
10173                                                                                                         player[i].targetanimation=sneakanim;
10174                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10175                                                                                                         player[i].targetframe=0;
10176                                                                                                 }
10177                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10178                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10179                                                                                                 }
10180                                                                                                 if(player[i].targetanimation==hanganim){
10181                                                                                                         player[i].currentanimation=jumpdownanim;
10182                                                                                                         player[i].targetanimation=jumpdownanim;
10183                                                                                                         player[i].target=0;
10184                                                                                                         player[i].currentframe=0;
10185                                                                                                         player[i].targetframe=1;
10186                                                                                                         player[i].velocity=0;
10187                                                                                                         player[i].velocity.y+=gravity;
10188                                                                                                         player[i].coords.y-=1.4;
10189                                                                                                         player[i].grabdelay=1;
10190                                                                                                 }
10191                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10192                                                                                                         player[i].targetrotation+=180;
10193                                                                                                 movekey=1;
10194                                                                                         }
10195                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10196                                                                                                 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)){
10197                                                                                                         player[i].jumpstart=0;
10198                                                                                                         player[i].targetanimation=jumpupanim;
10199                                                                                                         player[i].target=0;
10200                                                                                                         player[i].targetframe=0;
10201                                                                                                         player[i].rotation=player[i].targetrotation;
10202                                                                                                         player[i].transspeed=20;
10203                                                                                                         player[i].FootLand(0,1);
10204                                                                                                         player[i].FootLand(1,1);
10205
10206                                                                                                         facing=0;
10207                                                                                                         facing.z=-1;
10208                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10209
10210                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10211                                                                                                         if(!movekey)player[i].velocity=0;
10212
10213                                                                                                         //Dodge sweep?
10214                                                                                                         target=-2;
10215                                                                                                         if(numplayers>1)
10216                                                                                                                 for(j=0;j<numplayers;j++){
10217                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10218                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10219                                                                                                                                         if(target>=0)target=-1;
10220                                                                                                                                         else target=j;
10221                                                                                                                                 }
10222                                                                                                                         }
10223                                                                                                                 }
10224                                                                                                                 if(target>=0)player[i].velocity.y=1;
10225                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10226                                                                                                                         player[i].velocity.y=7;
10227                                                                                                                         player[i].crouchtogglekeydown=1;
10228                                                                                                                 }
10229                                                                                                                 else player[i].velocity.y=5;
10230
10231                                                                                                                 if(mousejump&&i==0&&debugmode){
10232                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10233                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10234                                                                                                                 }
10235
10236                                                                                                                 player[i].coords.y+=.2;
10237                                                                                                                 player[i].jumppower-=1;
10238
10239                                                                                                                 static float gLoc[3];
10240                                                                                                                 static float vel[3];
10241                                                                                                                 gLoc[0]=player[i].coords.x;
10242                                                                                                                 gLoc[1]=player[i].coords.y;
10243                                                                                                                 gLoc[2]=player[i].coords.z;
10244                                                                                                                 vel[0]=player[i].velocity.x;
10245                                                                                                                 vel[1]=player[i].velocity.y;
10246                                                                                                                 vel[2]=player[i].velocity.z;
10247
10248                                                                                                                 if(i==0){
10249                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
10250                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10251                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
10252                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
10253                                                                                                                 }
10254
10255                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
10256                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10257                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
10258                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
10259                                                                                                 }
10260                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10261                                                                                                         player[i].targetanimation=player[i].getLanding();
10262                                                                                                         player[i].landhard=0;
10263                                                                                                         player[i].target=0;
10264                                                                                                         player[i].targetframe=2;
10265                                                                                                         player[i].jumpstart=1;
10266                                                                                                         player[i].tempdeltav=deltav;
10267                                                                                                 }
10268                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10269                                                                                                         if(player[i].jumppower>multiplier*6){
10270                                                                                                                 player[i].velocity.y+=multiplier*6;
10271                                                                                                                 player[i].jumppower-=multiplier*6;
10272                                                                                                         }
10273                                                                                                         if(player[i].jumppower<=multiplier*6){
10274                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10275                                                                                                                 player[i].jumppower=0;
10276                                                                                                         }
10277                                                                                                 }
10278                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
10279                                                                                         }
10280
10281                                                                                         if(!movekey){
10282                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10283                                                                                                         player[i].targetanimation=player[i].getStop();
10284                                                                                                         player[i].target=0;
10285                                                                                                         player[i].targetframe=0;
10286                                                                                                 }
10287                                                                                                 if(player[i].targetanimation==sneakanim){
10288                                                                                                         player[i].targetanimation=player[i].getCrouch();
10289                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10290                                                                                                         player[i].targetframe=0;
10291                                                                                                 }
10292                                                                                         }
10293                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10294                                                                                                 player[i].targetanimation=player[i].getStop();
10295                                                                                                 player[i].target=0;
10296                                                                                                 player[i].targetframe=0;
10297                                                                                         }
10298                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10299                                                                                                 player[i].targetanimation=player[i].getStop();
10300                                                                                                 player[i].target=0;
10301                                                                                                 player[i].targetframe=0;
10302                                                                                         }
10303                                                                                 }
10304                                                                 }
10305                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10306                                                         }
10307
10308                                                         //Rotation
10309                                                         for(k=0;k<numplayers;k++){
10310                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10311                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10312                                                                         else player[k].rotation+=360;
10313                                                                 }
10314
10315                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10316                                                                         player[k].targetanimation=player[k].getStop();
10317                                                                         player[k].targetframe=0;
10318                                                                         player[k].target=0;
10319                                                                 }
10320
10321                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10322                                                                         player[k].targettilt=0;
10323                                                                 }
10324                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10325                                                                         player[k].targettilt=0;
10326                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10327                                                                         player[k].jumppower+=multiplier*7;
10328                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10329                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10330                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10331                                                                 }
10332
10333                                                                 if(player[k].isRun()){
10334                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10335                                                                 }
10336
10337                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10338                                                                 else if(player[k].tilt>player[k].targettilt){
10339                                                                         player[k].tilt-=multiplier*150;
10340                                                                 }
10341                                                                 else if(player[k].tilt<player[k].targettilt){
10342                                                                         player[k].tilt+=multiplier*150;
10343                                                                 }
10344
10345                                                                 player[k].grabdelay-=multiplier;
10346                                                         }
10347
10348                                                         for(k=0;k<numplayers;k++){
10349                                                                 player[k].DoAnimations();
10350                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10351                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10352                                                         }
10353
10354                                                         objects.DoStuff();
10355                                                         /*
10356                                                         player[0].righthandmorphstart=0;
10357                                                         player[0].righthandmorphend=1;
10358                                                         player[0].lefthandmorphstart=0;
10359                                                         player[0].lefthandmorphend=1;
10360                                                         player[0].headmorphstart=0;
10361                                                         player[0].headmorphend=2;*/
10362
10363                                                         /*
10364                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10365                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10366                                                         player[0].righthandmorphend=1;
10367                                                         player[0].targetrighthandmorphness=1;
10368
10369                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10370                                                         player[0].lefthandmorphend=0;
10371                                                         player[0].targetlefthandmorphness=1;
10372
10373                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10374                                                         player[0].headmorphend=2;
10375                                                         player[0].targetheadmorphness=1;
10376                                                         }
10377                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10378                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10379                                                         player[0].righthandmorphend=0;
10380                                                         player[0].targetrighthandmorphness=1;
10381
10382                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10383                                                         player[0].lefthandmorphend=1;
10384                                                         player[0].targetlefthandmorphness=1;
10385
10386                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10387                                                         player[0].headmorphend=0;
10388                                                         player[0].targetheadmorphness=1;
10389                                                         }
10390                                                         */
10391                                                         if(numenvsounds!=0)
10392                                                                 for(j=numenvsounds-1;j>=0;j--){
10393                                                                         envsoundlife[j]-=multiplier;
10394                                                                         if(envsoundlife[j]<0){
10395                                                                                 numenvsounds--;
10396                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10397                                                                                 envsound[j]=envsound[numenvsounds];
10398                                                                         }
10399                                                                 }
10400                                                                 if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
10401                                                                 if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
10402
10403                                                                 if(tutoriallevel==1){
10404                                                                         XYZ temp;
10405                                                                         XYZ temp2;
10406                                                                         XYZ temp3;
10407                                                                         XYZ oldtemp;
10408                                                                         XYZ oldtemp2;
10409                                                                         temp.x=1011;
10410                                                                         temp.y=84;
10411                                                                         temp.z=491;
10412                                                                         temp2.x=1025;
10413                                                                         temp2.y=75;
10414                                                                         temp2.z=447;
10415                                                                         temp3.x=1038;
10416                                                                         temp3.y=76;
10417                                                                         temp3.z=453;
10418                                                                         oldtemp=temp;
10419                                                                         oldtemp2=temp2;
10420                                                                         if(tutorialstage>=51)
10421                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10422                                                     OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
10423                                                                                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
10424
10425                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10426                                                                                         OPENAL_SetPaused(channels[stream_music3], false);
10427                                                                                         OPENAL_SetVolume(channels[stream_music3], 256);
10428
10429                                                                                         gameon=0;
10430                                                                                         mainmenu=5;
10431
10432                                                                                         float gLoc[3]={0,0,0};
10433                                                                                         float vel[3]={0,0,0};
10434                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10435                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10436                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10437                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10438                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10439                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10440
10441                                                                                         flashr=1;
10442                                                                                         flashg=0;
10443                                                                                         flashb=0;
10444                                                                                         flashamount=1;
10445                                                                                         flashdelay=1;
10446                                                                                 }
10447                                                                                 if(tutorialstage<51)
10448                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10449                                                                                                 float gLoc[3];
10450                                                                                                 float vel[3];
10451                                                                                                 gLoc[0]=player[0].coords.x;
10452                                                                                                 gLoc[1]=player[0].coords.y;
10453                                                                                                 gLoc[2]=player[0].coords.z;
10454                                                                                                 vel[0]=0;
10455                                                                                                 vel[1]=0;
10456                                                                                                 vel[2]=0;
10457                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10458                                                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10459                                                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10460                                                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10461
10462                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10463
10464                                                                                                 flashr=1;
10465                                                                                                 flashg=1;
10466                                                                                                 flashb=1;
10467                                                                                                 flashamount=1;
10468                                                                                                 flashdelay=1;
10469                                                                                         }
10470                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10471                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10472                                                                                                         float gLoc[3];
10473                                                                                                         float vel[3];
10474                                                                                                         gLoc[0]=player[1].coords.x;
10475                                                                                                         gLoc[1]=player[1].coords.y;
10476                                                                                                         gLoc[2]=player[1].coords.z;
10477                                                                                                         vel[0]=0;
10478                                                                                                         vel[1]=0;
10479                                                                                                         vel[2]=0;
10480                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10481                                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10482                                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10483                                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10484
10485                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10486                                                                                                                 if(Random()%2==0){
10487                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10488                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10489                                                                                                                         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;
10490                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10491                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10492                                                                                                                 }
10493                                                                                                         }
10494
10495                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10496                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10497                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10498                                                                                                                 if(Random()%2==0){
10499                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10500                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10501                                                                                                                         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;
10502                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10503                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10504                                                                                                                 }
10505                                                                                                         }
10506                                                                                                 }
10507                                                                 }
10508
10509
10510                                                                 //3d sound
10511                                                                 static float gLoc[3];
10512                                                                 gLoc[0]=viewer.x;
10513                                                                 gLoc[1]=viewer.y;
10514                                                                 gLoc[2]=viewer.z;
10515                                                                 static float vel[3];
10516                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10517                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10518                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10519
10520                                                                 //Set orientation with forward and up vectors
10521                                                                 static XYZ upvector;
10522                                                                 upvector=0;
10523                                                                 upvector.z=-1;
10524
10525                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10526                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10527
10528                                                                 facing=0;
10529                                                                 facing.z=-1;
10530
10531                                                                 facing=DoRotation(facing,-rotation2,0,0);
10532                                                                 facing=DoRotation(facing,0,0-rotation,0);
10533
10534
10535                                                                 static float ori[6];
10536                                                                 ori[0] = -facing.x;
10537                                                                 ori[1] = facing.y;
10538                                                                 ori[2] = -facing.z;
10539                                                                 ori[3] = -upvector.x;
10540                                                                 ori[4] = upvector.y;
10541                                                                 ori[5] = -upvector.z;
10542
10543                                                                 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10544                                                                 OPENAL_Update();
10545
10546                                                                 oldviewer=viewer;
10547                 }
10548         }
10549
10550         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10551                 Screenshot();
10552                 freezetogglekeydown=1;
10553         }
10554 }
10555
10556 void    Game::TickOnce(){
10557         //if(!console){
10558         if(!mainmenu)
10559                 if(directing||indialogue==-1){
10560                         rotation+=deltah*.7;
10561                         if(!invertmouse)rotation2+=deltav*.7;
10562                         if(invertmouse)rotation2-=deltav*.7;
10563                         if(rotation2>90)rotation2=90;
10564                         if(rotation2<-70)rotation2=-70;
10565                 }
10566                 if(mainmenu)rotation+=multiplier*5;
10567       
10568                 //}
10569 }
10570
10571 void    Game::TickOnceAfter(){
10572         static XYZ colviewer;
10573         static XYZ coltarget;
10574         static XYZ target;
10575         static XYZ col;
10576         static float brotate;
10577         static XYZ facing;
10578         static int i,j;
10579         static float changedelay;
10580         static bool alldead;
10581         static float unseendelay;
10582         static float cameraspeed;
10583
10584         if(!mainmenu){
10585
10586                 if(environment==snowyenvironment)music1=stream_music1snow;
10587                 if(environment==grassyenvironment)music1=stream_music1grass;
10588                 if(environment==desertenvironment)music1=stream_music1desert;
10589
10590                 realthreat=0;
10591
10592                 musictype=music1;
10593                 for(i=0;i<numplayers;i++){
10594                         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)){
10595                                 musictype=stream_music2;
10596                                 realthreat=1;
10597                         }
10598                 }
10599                 if(player[0].dead)musictype=stream_music3;
10600
10601
10602                 if(musictype==stream_music2){
10603                         unseendelay=1;
10604                 }
10605
10606                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
10607                         unseendelay-=multiplier;
10608                         if(unseendelay>0){
10609                                 musictype=stream_music2;
10610                         }
10611                 }
10612
10613
10614                 if(loading==2){
10615                         musictype=stream_music3;
10616                         musicvolume[2]=512;
10617                         musicvolume[0]=0;
10618                         musicvolume[1]=0;
10619                         musicvolume[3]=0;
10620                 }
10621
10622                 if(musictoggle){
10623                         if(musictype!=oldmusictype&&musictype==stream_music2){
10624                                 static float gLoc[3];
10625                                 static float vel[3];
10626                                 gLoc[0]=cameraloc.x;
10627                                 gLoc[1]=cameraloc.y;
10628                                 gLoc[2]=cameraloc.z;
10629                                 vel[0]=0;
10630                                 vel[1]=0;
10631                                 vel[2]=0;
10632                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
10633                                 OPENAL_SetVolume(channels[alarmsound], 512);
10634                                 OPENAL_SetPaused(channels[alarmsound], false);
10635
10636                         }
10637                 }
10638                 musicselected=musictype;
10639
10640                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
10641                 else musicvolume[0]-=multiplier*450;
10642                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
10643                 else musicvolume[1]-=multiplier*450;
10644                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
10645                 else musicvolume[2]-=multiplier*450;
10646                 /*
10647                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
10648                 else musicvolume[0]-=multiplier*450;
10649                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
10650                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
10651                 else musicvolume[1]-=multiplier*100;
10652                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
10653                 else musicvolume[2]-=multiplier*450;*/
10654
10655                 for(i=0;i<3;i++){
10656                         if(musicvolume[i]<0)musicvolume[i]=0;
10657                         if(musicvolume[i]>512)musicvolume[i]=512;
10658                 }
10659
10660                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
10661
10662                 if(musictoggle){
10663                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
10664                                 PlayStreamEx( music1, strm[music1], NULL, true);
10665                                 OPENAL_SetPaused(channels[music1], false);
10666                         }
10667                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
10668                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
10669                                 OPENAL_SetPaused(channels[stream_music2], false);
10670                         }
10671                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
10672                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10673                                 OPENAL_SetPaused(channels[stream_music3], false);
10674                         }
10675                 }
10676
10677                 if(!musictoggle){
10678                         OPENAL_SetPaused(channels[music1], true);
10679                         OPENAL_SetPaused(channels[stream_music2], true);
10680                         OPENAL_SetPaused(channels[stream_music3], true);
10681
10682                         for(i=0;i<4;i++){
10683                                 oldmusicvolume[i]=0;
10684                                 musicvolume[i]=0;
10685                         }
10686                 }
10687
10688                 if(musictoggle){
10689                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
10690                                 OPENAL_SetPaused(channels[music1], true);
10691                         }
10692                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
10693                                 OPENAL_SetPaused(channels[stream_music2], true);
10694                         }
10695                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
10696                                 OPENAL_SetPaused(channels[stream_music3], true);
10697                         }
10698
10699                         if(musicvolume[0]!=oldmusicvolume[0]){
10700                                 OPENAL_SetVolume(channels[music1], musicvolume[0]);
10701                         }
10702                         if(musicvolume[1]!=oldmusicvolume[1]){
10703                                 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
10704                         }
10705                         if(musicvolume[2]!=oldmusicvolume[2]){
10706                                 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
10707                         }
10708
10709                         for(i=0;i<3;i++){
10710                                 oldmusicvolume[i]=musicvolume[i];
10711                         }
10712                 }
10713
10714                 killhotspot=2;
10715                 if(numhotspots)
10716                         for(i=0;i<numhotspots;i++){
10717                                 if(hotspottype[i]>10&&hotspottype[i]<20){
10718                                         if(player[hotspottype[i]-10].dead==0){
10719                                                 killhotspot=0;
10720                                         }
10721                                         else if(killhotspot==2)
10722                                                 killhotspot=1;
10723                                 }
10724                         }
10725                         if(killhotspot==2)killhotspot=0;
10726
10727
10728                         winhotspot=0;
10729                         if(numhotspots)
10730                                 for(i=0;i<numhotspots;i++){
10731                                         if(hotspottype[i]==-1){
10732                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
10733                                                         winhotspot=1;
10734                                         }
10735                                 }
10736
10737                                 int numalarmed=0;
10738                                 if(numplayers>1)
10739                                         for(i=1;i<numplayers;i++){
10740                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
10741                                         }
10742                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
10743
10744                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
10745                                                 if(player[0].dead&&changedelay<=0){
10746                                                         changedelay=1;
10747                                                         targetlevel=whichlevel;
10748                                                 }
10749                                                 alldead=1;
10750                                                 if(numplayers>1)
10751                                                         for(i=1;i<numplayers;i++){
10752                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
10753                                                         }
10754
10755
10756                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
10757                                                                 changedelay=1;
10758                                                                 targetlevel=whichlevel+1;
10759                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10760                                                         }
10761                                                         if(winhotspot||windialogue){
10762                                                                 changedelay=0.1;
10763                                                                 targetlevel=whichlevel+1;
10764                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10765                                                         }
10766
10767
10768                                                         if(killhotspot){
10769                                                                 changedelay=1;
10770                                                                 targetlevel=whichlevel+1;
10771                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10772                                                         }
10773
10774                                                         if(changedelay>0&&!player[0].dead&&!won){
10775                                                                 //high scores, awards, win
10776                                                                 if(campaign){
10777                                                                         won=1;
10778                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
10779                                                                         accountcampaignchoicesmade[accountactive]++;
10780                                                                         accountcampaignscore[accountactive]+=bonustotal;
10781                                                                         scoreadded=1;
10782                                                                         accountcampaigntime[accountactive]+=leveltime;
10783                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
10784
10785                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
10786                                                                 }
10787                                                                 else
10788                                                                 {
10789                                                                         won=1;
10790                                                                         if(!debugmode){
10791                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
10792                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;
10793                                                                         }
10794                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
10795
10796                                                                 }
10797                                                         }
10798                                         }
10799
10800                                         if(!winfreeze){
10801
10802                                                 if(leveltime<1){
10803                                                         loading=0;
10804                                                         changedelay=.1;
10805                                                         alldead=0;
10806                                                         winhotspot=0;
10807                                                         killhotspot=0;
10808                                                 }
10809
10810                                                 if(!editorenabled&&gameon&&!mainmenu){
10811                                                         if(changedelay!=-999)changedelay-=multiplier/7;
10812                                                         if(player[0].dead)targetlevel=whichlevel;
10813                                                         if(loading==2&&!campaign){
10814                                                                 flashr=1;
10815                                                                 flashg=0;
10816                                                                 flashb=0;
10817                                                                 flashamount=1;
10818                                                                 flashdelay=1;
10819                                                                 loadtime=0;
10820
10821                                                                 float gLoc[3]={0,0,0};
10822                                                                 float vel[3]={0,0,0};
10823                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10824                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10825                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10826                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
10827                                                                 OPENAL_SetPaused(channels[firestartsound], false);
10828                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10829
10830                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
10831                                                                         startbonustotal=bonustotal;
10832                                                                 }
10833                                                                 if(!player[0].dead)Loadlevel(targetlevel);
10834                                                                 if(player[0].dead)Loadlevel(whichlevel);
10835
10836                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10837                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10838                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10839                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10840                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10841                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10842
10843                                                                 loading=3;
10844                                                         }
10845                                                         if(loading==2&&targetlevel==whichlevel){
10846                                                                 flashr=1;
10847                                                                 flashg=0;
10848                                                                 flashb=0;
10849                                                                 flashamount=1;
10850                                                                 flashdelay=1;
10851                                                                 loadtime=0;
10852
10853                                                                 float gLoc[3]={0,0,0};
10854                                                                 float vel[3]={0,0,0};
10855                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10856                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10857                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10858                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
10859                                                                 OPENAL_SetPaused(channels[firestartsound], false);
10860                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10861
10862                                                                 for(i=0;i<255;i++){
10863                                                                         mapname[i]='\0';
10864                                                                 }
10865                                                                 mapname[0]=':';
10866                                                                 mapname[1]='D';
10867                                                                 mapname[2]='a';
10868                                                                 mapname[3]='t';
10869                                                                 mapname[4]='a';
10870                                                                 mapname[5]=':';
10871                                                                 mapname[6]='M';
10872                                                                 mapname[7]='a';
10873                                                                 mapname[8]='p';
10874                                                                 mapname[9]='s';
10875                                                                 mapname[10]=':';
10876                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
10877                                                                 Loadlevel(mapname);
10878
10879                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10880                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10881                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10882                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10883                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10884                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10885
10886                                                                 loading=3;
10887                                                         }
10888                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
10889                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
10890                         {
10891                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
10892                                                                                 winfreeze=1;
10893                                                                                 changedelay=-999;
10894                                                                         }
10895                                                                         if(player[0].dead)loading=1;
10896                                                                 }
10897                                                         }
10898                                                 }
10899
10900                                                 if(campaign)
10901                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
10902                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
10903                                                                         endgame=1;
10904                                                                 }
10905                                                         }
10906                                                         else if(mainmenu==0&&winfreeze){
10907                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
10908                                                                         stealthloading=1;
10909                                                                 else stealthloading=0;
10910
10911                                                                 if(!stealthloading){
10912                                                                         float gLoc[3]={0,0,0};
10913                                                                         float vel[3]={0,0,0};
10914                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10915                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10916                                                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10917                                                                         OPENAL_SetVolume(channels[firestartsound], 256);
10918                                                                         OPENAL_SetPaused(channels[firestartsound], false);
10919                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10920
10921                                                                         flashr=1;
10922                                                                         flashg=0;
10923                                                                         flashb=0;
10924                                                                         flashamount=1;
10925                                                                         flashdelay=1;
10926                                                                 }
10927
10928                                                                 startbonustotal=0;
10929
10930                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
10931                                                                 //campaignnumlevels=0;
10932                                                                 //accountcampaignchoicesmade[accountactive]=0;
10933                                                                 ipstream.ignore(256,':');
10934                                                                 ipstream >> campaignnumlevels;
10935                                                                 for(i=0;i<campaignnumlevels;i++){
10936                                                                         ipstream.ignore(256,':');
10937                                                                         ipstream.ignore(256,':');
10938                                                                         ipstream.ignore(256,' ');
10939                                                                         ipstream >> campaignmapname[i];
10940                                                                         ipstream.ignore(256,':');
10941                                                                         ipstream >> campaigndescription[i];
10942                                                                         for(j=0;j<256;j++){
10943                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
10944                                                                         }
10945                                                                         ipstream.ignore(256,':');
10946                                                                         ipstream >> campaignchoosenext[i];
10947                                                                         ipstream.ignore(256,':');
10948                                                                         ipstream >> campaignnumnext[i];
10949                                                                         if(campaignnumnext[i])
10950                                                                                 for(j=0;j<campaignnumnext[i];j++){
10951                                                                                         ipstream.ignore(256,':');
10952                                                                                         ipstream >> campaignnextlevel[i][j];
10953                                                                                         campaignnextlevel[i][j]-=1;
10954                                                                                 }
10955                                                                                 ipstream.ignore(256,':');
10956                                                                                 ipstream >> campaignlocationx[i];
10957                                                                                 ipstream.ignore(256,':');
10958                                                                                 ipstream >> campaignlocationy[i];
10959                                                                 }
10960                                                                 ipstream.close();
10961
10962                                                                 for(i=0;i<campaignnumlevels;i++){
10963                                                                         levelvisible[i]=0;
10964                                                                         levelhighlight[i]=0;
10965                                                                 }
10966
10967
10968                                                                 for(i=0;i<campaignnumlevels;i++){
10969                                                                         levelvisible[i]=0;
10970                                                                         levelhighlight[i]=0;
10971                                                                 }
10972
10973                                                                 levelorder[0]=0;
10974                                                                 levelvisible[0]=1;
10975                                                                 if(accountcampaignchoicesmade[accountactive])
10976                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
10977                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
10978                                                                                 levelvisible[levelorder[i+1]]=1;
10979                                                                         }
10980                                                                         int whichlevelstart;
10981                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
10982                                                                         if(whichlevelstart<0){
10983                                                                                 campaignchoicenum=1;
10984                                                                                 campaignchoicewhich[0]=0;
10985                                                                         }
10986                                                                         else
10987                                                                         {
10988                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
10989                                                                                 if(campaignchoicenum)
10990                                                                                         for(i=0;i<campaignchoicenum;i++){
10991                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
10992                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
10993                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
10994                                                                                         }
10995                                                                         }
10996
10997                                                                         loading=2;
10998                                                                         loadtime=0;
10999                                                                         targetlevel=7;
11000                                                                         //if(firstload)TickOnceAfter();
11001                                                                         if(!firstload)LoadStuff();
11002                                                                         //else {
11003                                                                         for(i=0;i<255;i++){
11004                                                                                 mapname[i]='\0';
11005                                                                         }
11006                                                                         mapname[0]=':';
11007                                                                         mapname[1]='D';
11008                                                                         mapname[2]='a';
11009                                                                         mapname[3]='t';
11010                                                                         mapname[4]='a';
11011                                                                         mapname[5]=':';
11012                                                                         mapname[6]='M';
11013                                                                         mapname[7]='a';
11014                                                                         mapname[8]='p';
11015                                                                         mapname[9]='s';
11016                                                                         mapname[10]=':';
11017
11018                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11019                                                                         //accountcampaignchoicesmade[accountactive]++;
11020
11021
11022                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11023                                                                         whichchoice=0;
11024                                                                         visibleloading=1;
11025                                                                         stillloading=1;
11026                                                                         Loadlevel(mapname);
11027                                                                         campaign=1;
11028                                                                         mainmenu=0;
11029                                                                         gameon=1;
11030                                                                         OPENAL_SetPaused(channels[stream_music3], true);
11031
11032                                                                         stealthloading=0;
11033                                                         }
11034
11035                                                         if(loading==3)loading=0;
11036
11037                                         }
11038
11039                                         oldmusictype=musictype;
11040         }
11041
11042         facing=0;
11043         facing.z=-1;
11044
11045         facing=DoRotation(facing,-rotation2,0,0);
11046         facing=DoRotation(facing,0,0-rotation,0);
11047         viewerfacing=facing;
11048
11049         brotate=0;
11050         if(!cameramode){
11051                 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;
11052                 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;
11053                 target.y+=.1;
11054                 if(player[0].skeleton.free){
11055                         for(i=0;i<player[0].skeleton.num_joints;i++){
11056                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
11057                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11058                         }
11059                         target.y+=.1;
11060                 }
11061                 if(player[0].skeleton.free!=2&&!autocam){
11062                         cameraspeed=20;
11063                         if(findLengthfast(&player[0].velocity)>400){
11064                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11065                         }
11066                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11067                         coltarget=target-cameraloc;
11068                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11069                         else {
11070                                 Normalise(&coltarget);
11071                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11072                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11073                         }
11074                         if(editorenabled)cameraloc=target;
11075                         cameradist+=multiplier*5;
11076                         if(cameradist>2.3)cameradist=2.3;
11077                         viewer=cameraloc-facing*cameradist;
11078                         colviewer=viewer;
11079                         coltarget=cameraloc;
11080                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11081                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11082                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11083                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11084                                         colviewer=viewer;
11085                                         coltarget=cameraloc;
11086                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11087                                 }
11088                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11089                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11090                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11091                                                 colviewer=viewer;
11092                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11093                                                         viewer=colviewer;
11094                                                 }
11095                                         }
11096                                         cameradist=findDistance(&viewer,&target);
11097                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11098                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11099                                         }
11100                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11101                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11102                                         }
11103                 }
11104                 if(player[0].skeleton.free!=2&&autocam){
11105                         cameraspeed=20;
11106                         if(findLengthfast(&player[0].velocity)>400){
11107                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11108                         }
11109                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11110                         cameradist+=multiplier*5;
11111                         if(cameradist>3.3)cameradist=3.3;
11112                         coltarget=target-cameraloc;
11113                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11114                         else if(findLengthfast(&coltarget)>1)
11115                         {
11116                                 Normalise(&coltarget);
11117                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11118                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11119                         }
11120                         if(editorenabled)cameraloc=target;
11121                         viewer=cameraloc;
11122                         colviewer=viewer;
11123                         coltarget=cameraloc;
11124                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11125                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11126                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11127                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11128                                         colviewer=viewer;
11129                                         coltarget=cameraloc;
11130                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11131                                 }
11132                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11133                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11134                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11135                                                 colviewer=viewer;
11136                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11137                                                         viewer=colviewer;
11138                                                 }
11139                                         }
11140                                         cameradist=findDistance(&viewer,&target);
11141                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11142                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11143                                         }
11144                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11145                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11146                                         }
11147                 }
11148                 if(camerashake>.8)camerashake=.8;
11149                 //if(woozy>10)woozy=10;
11150                 //woozy+=multiplier;
11151                 woozy+=multiplier;
11152                 if(player[0].dead)camerashake=0;
11153                 if(player[0].dead)woozy=0;
11154                 camerashake-=multiplier*2;
11155                 blackout-=multiplier*2;
11156                 //if(player[0].isCrouch())woozy-=multiplier*8;
11157                 if(camerashake<0)camerashake=0;
11158                 if(blackout<0)blackout=0;
11159                 //if(woozy<0)woozy=0;
11160                 if(camerashake){
11161                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11162                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11163                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11164                 }
11165         }
11166 }