]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
Reverted all changes to 'GameTick.cpp' because it broke Lugaru codebase badly
[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 /********************> Tick() <*****/
226 extern OPENAL_STREAM * strm[20];
227 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
228 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
229
230 extern void ScreenShot(const char * fname);
231 void Screenshot (void)
232 {
233         char temp[1024];
234         time_t  t = time(NULL);
235         struct  tm *tme = localtime(&t);
236         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);
237
238         #if defined(_WIN32)
239         mkdir("Screenshots");
240         #else
241         mkdir("Screenshots", S_IRWXU);
242         #endif
243
244         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
245
246         /*FSSpec                                MAC_file;
247         GraphicsExportComponent QT_exporter;
248         OSErr                           MAC_error_code;
249         CGrafPtr                        MAC_currentPort;
250         GDHandle                        MAC_currentDevice;
251         unsigned char*          MAC_pixels;
252         Rect                            MAC_picture_rectangle;
253         GWorldPtr                       MAC_offscreen_graphics_port;
254
255         static int numscreenshots=0;
256
257         // Make an FSSpec
258         static char buf[256];
259         if(numscreenshots==0){
260         buf[0]=26;
261         buf[1]=':';
262         buf[2]='S';
263         buf[3]='c';
264         buf[4]='r';
265         buf[5]='e';
266         buf[6]='e';
267         buf[7]='n';
268         buf[8]='s';
269         buf[9]='h';
270         buf[10]='o';
271         buf[11]='t';
272         buf[12]='s';
273         buf[13]=':';
274         buf[14]='S';
275         buf[15]='c';
276         buf[16]='r';
277         buf[17]='e';
278         buf[18]='e';
279         buf[19]='n';
280         buf[20]='s';
281         buf[21]='h';
282         buf[22]='o';
283         buf[23]='t';
284         buf[24]='0';
285         buf[25]='0';
286         buf[26]='0';
287         }
288
289         FInfo *fndrInfo;
290         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
291         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
292         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
293         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
294         numscreenshots++;
295         buf[26]++;
296         if(buf[26]==':'){
297         buf[26]='0';
298         buf[25]++;
299         if(buf[25]==':'){
300         buf[25]='0';
301         buf[24]++;
302         if(buf[24]==':'){
303         buf[24]='9';
304         buf[25]='9';
305         buf[26]='9';
306         }
307         }
308         }
309         }
310         }
311
312
313         // Get the GWorld
314         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
315         //assert(MAC_gWorld != NULL);
316
317         // Allocate memory for loading image
318         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
319         if (MAC_pixels == NULL) {
320         //UTIL_Error("Could not create Texture data.");
321         return;
322         }
323
324         // Get GWorld
325         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
326
327         // Make a picture Rectangle
328         MAC_picture_rectangle.left = 0;
329         MAC_picture_rectangle.right = screenwidth;
330         MAC_picture_rectangle.top = 0;
331         MAC_picture_rectangle.bottom = screenheight;
332
333         // Create new offscreen GWorld
334         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
335         if (MAC_error_code)     {
336         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
337         delete MAC_pixels;
338         //UTIL_Error("Could not create offscreen GWorld. ");
339         return;
340
341         }
342
343         // Copy OpenGL Context to new GWorld
344         glReadBuffer(GL_FRONT);
345         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
346
347         // Swizzle texture
348         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
349         unsigned char temp = MAC_pixels[byte+0];
350         MAC_pixels[byte+0] = MAC_pixels[byte+3];
351         MAC_pixels[byte+3] = MAC_pixels[byte+2];
352         MAC_pixels[byte+2] = MAC_pixels[byte+1];
353         MAC_pixels[byte+1] = temp;
354         }
355
356         // Flip the image  :(   This could probably be optimized
357         int vert;
358         int src_index;
359         int dst_index;
360         unsigned char temp;
361         for (int horz = 0; horz < screenwidth; ++horz)
362         for (vert = 0; vert < screenheight / 2; ++vert) {
363         src_index = (screenwidth * vert + horz) * 4;
364         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
365
366         temp=MAC_pixels[src_index+0];
367         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
368         MAC_pixels[dst_index+0]=temp;
369
370         temp=MAC_pixels[src_index+1];
371         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
372         MAC_pixels[dst_index+1]=temp;
373
374         temp=MAC_pixels[src_index+2];
375         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
376         MAC_pixels[dst_index+2]=temp;
377
378         temp=MAC_pixels[src_index+3];
379         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
380         MAC_pixels[dst_index+3]=temp;
381         }
382
383
384
385         // Export the Gworld
386         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
387         if (MAC_error_code) {
388         //UTIL_Warning("Unable to export screenshot.");
389         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
390         ::DisposeGWorld(MAC_offscreen_graphics_port);
391         delete MAC_pixels;
392         return;
393         }
394
395         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
396         if (MAC_error_code) {
397         ::CloseComponent(QT_exporter);
398         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
399         ::DisposeGWorld(MAC_offscreen_graphics_port);
400         delete MAC_pixels;
401         //UTIL_Warning("Unable to export screenshot.");
402         return;
403         }
404
405         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
406         if (MAC_error_code) {
407         ::CloseComponent(QT_exporter);
408         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
409         ::DisposeGWorld(MAC_offscreen_graphics_port);
410         delete MAC_pixels;
411         //UTIL_Warning("Unable to export screenshot.");
412         return;
413         }
414
415         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
416         if (MAC_error_code) {
417         ::CloseComponent(QT_exporter);
418         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
419         ::DisposeGWorld(MAC_offscreen_graphics_port);
420         delete MAC_pixels;
421         //UTIL_Warning("Unable to export screenshot.");
422         return;
423         }
424
425         ::CloseComponent(QT_exporter);
426         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
427         ::DisposeGWorld(MAC_offscreen_graphics_port);
428
429         delete MAC_pixels;*/
430 }
431
432
433
434 void    Game::SetUpLighting(){
435         if(environment==snowyenvironment){
436                 light.color[0]=.65;
437                 light.color[1]=.65;
438                 light.color[2]=.7;
439                 light.ambient[0]=.4;
440                 light.ambient[1]=.4;
441                 light.ambient[2]=.44;
442         }
443         if(environment==desertenvironment){
444                 light.color[0]=.95;
445                 light.color[1]=.95;
446                 light.color[2]=.95;
447                 light.ambient[0]=.4;
448                 light.ambient[1]=.35;
449                 light.ambient[2]=.3;
450         }
451
452         if(environment==grassyenvironment){
453                 light.color[0]=.95;
454                 light.color[1]=.95;
455                 light.color[2]=1;
456                 light.ambient[0]=.4;
457                 light.ambient[1]=.4;
458                 light.ambient[2]=.44;
459         }
460         if(!skyboxtexture){
461                 light.color[0]=1;
462                 light.color[1]=1;
463                 light.color[2]=1;
464                 light.ambient[0]=.4;
465                 light.ambient[1]=.4;
466                 light.ambient[2]=.4;
467         }
468         float average;
469         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
470         light.color[0]*=(skyboxlightr+average)/2;
471         light.color[1]*=(skyboxlightg+average)/2;
472         light.color[2]*=(skyboxlightb+average)/2;
473         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
474         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
475         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
476         /*
477         light.ambient[0]=0;
478         light.ambient[1]=0;
479         light.ambient[2]=0;     */
480 }
481
482 int Game::findPathDist(int start,int end){
483         int i,j,k,smallestcount,count,connected;
484         int last,last2,last3,last4;
485         int closest;
486
487         smallestcount=1000;
488         for(i=0;i<50;i++){
489                 count=0;
490                 last=start;
491                 last2=-1;
492                 last3=-1;
493                 last4=-1;
494                 while(last!=end&&count<30){
495                         closest=-1;
496                         for(j=0;j<numpathpoints;j++){
497                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
498                                 {
499                                         connected=0;
500                                         if(numpathpointconnect[j])
501                                                 for(k=0;k<numpathpointconnect[j];k++){
502                                                         if(pathpointconnect[j][k]==last)connected=1;
503                                                 }
504                                                 if(!connected)
505                                                         if(numpathpointconnect[last])
506                                                                 for(k=0;k<numpathpointconnect[last];k++){
507                                                                         if(pathpointconnect[last][k]==j)connected=1;
508                                                                 }
509                                                                 if(connected)
510                                                                         if(closest==-1||Random()%2==0){
511                                                                                 closest=j;
512                                                                         }
513                                 }
514                         }
515                         last4=last3;
516                         last3=last2;
517                         last2=last;
518                         last=closest;
519                         count++;
520                 }
521                 if(count<smallestcount)smallestcount=count;
522         }
523         return smallestcount;
524 }
525
526 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
527         static XYZ colpoint,colviewer,coltarget;
528         static float minx,minz,maxx,maxz,miny,maxy;
529         static int i;
530
531         //startpoint.y+=.7;
532         //endpoint.y+=.7;
533         //startpoint.y-=.1;
534         //endpoint.y-=.1;
535
536         minx=startpoint.x;
537         if(minx>endpoint.x)minx=endpoint.x;
538         miny=startpoint.y;
539         if(miny>endpoint.y)miny=endpoint.y;
540         minz=startpoint.z;
541         if(minz>endpoint.z)minz=endpoint.z;
542
543         maxx=startpoint.x;
544         if(maxx<endpoint.x)maxx=endpoint.x;
545         maxy=startpoint.y;
546         if(maxy<endpoint.y)maxy=endpoint.y;
547         maxz=startpoint.z;
548         if(maxz<endpoint.z)maxz=endpoint.z;
549
550         minx-=1;
551         miny-=1;
552         minz-=1;
553         maxx+=1;
554         maxy+=1;
555         maxz+=1;
556
557         for(i=0;i<objects.numobjects;i++){
558                 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){
559                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
560                                 colviewer=startpoint;
561                                 coltarget=endpoint;
562                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
563                         }
564                 }
565         }
566
567         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
568
569         return -1;
570 }
571
572 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
573         static XYZ colpoint,colviewer,coltarget;
574         static float minx,minz,maxx,maxz,miny,maxy;
575         static int i;
576
577         //startpoint.y+=.7;
578         //endpoint.y+=.7;
579         //startpoint.y-=.1;
580         //endpoint.y-=.1;
581
582         minx=startpoint.x;
583         if(minx>endpoint.x)minx=endpoint.x;
584         miny=startpoint.y;
585         if(miny>endpoint.y)miny=endpoint.y;
586         minz=startpoint.z;
587         if(minz>endpoint.z)minz=endpoint.z;
588
589         maxx=startpoint.x;
590         if(maxx<endpoint.x)maxx=endpoint.x;
591         maxy=startpoint.y;
592         if(maxy<endpoint.y)maxy=endpoint.y;
593         maxz=startpoint.z;
594         if(maxz<endpoint.z)maxz=endpoint.z;
595
596         minx-=1;
597         miny-=1;
598         minz-=1;
599         maxx+=1;
600         maxy+=1;
601         maxz+=1;
602
603         if(what!=1000){
604                 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){
605                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
606                                 colviewer=startpoint;
607                                 coltarget=endpoint;
608                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
609                         }
610                 }
611         }
612
613         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
614
615         return -1;
616 }
617
618 void    Game::Setenvironment(int which)
619 {
620         LOGFUNC;
621
622         LOG(" Setting environment...");
623
624         float temptexdetail;
625         environment=which;
626 /*
627         OPENAL_SetPaused(channels[music1snow], true);
628         OPENAL_SetPaused(channels[music1grass], true);
629         OPENAL_SetPaused(channels[music1desert], true);
630         OPENAL_SetPaused(channels[wind], true);
631         OPENAL_SetPaused(channels[desertambient], true);
632 */
633         OPENAL_SetPaused(channels[stream_music1snow], true);
634         OPENAL_SetPaused(channels[stream_music1grass], true);
635         OPENAL_SetPaused(channels[stream_music1desert], true);
636         OPENAL_SetPaused(channels[stream_wind], true);
637         OPENAL_SetPaused(channels[stream_desertambient], true);
638
639
640         if(environment==snowyenvironment){
641                 windvector=0;
642                 windvector.z=3;
643                 if(ambientsound){
644                         //PlaySoundEx( wind, samp[wind], NULL, true);
645                         PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
646                         OPENAL_SetPaused(channels[stream_wind], false);
647                         OPENAL_SetVolume(channels[stream_wind], 256);
648                 }
649
650                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
651                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
652                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
653                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
654
655                 OPENAL_Sample_Free(samp[footstepsound]);
656                 OPENAL_Sample_Free(samp[footstepsound2]);
657                 OPENAL_Sample_Free(samp[footstepsound3]);
658                 OPENAL_Sample_Free(samp[footstepsound4]);
659                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
660                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
661                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone1.ogg", OPENAL_HW3D, 0, 0);
662                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone2.ogg", OPENAL_HW3D, 0, 0);
663                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
664                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
665                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
666                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
667
668                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
669
670                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
671
672                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
673
674
675
676
677                 temptexdetail=texdetail;
678                 if(texdetail>1)texdetail=4;
679                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
680                         ":Data:Textures:Skybox(snow):Left.jpg",
681                         ":Data:Textures:Skybox(snow):Back.jpg",
682                         ":Data:Textures:Skybox(snow):Right.jpg",
683                         ":Data:Textures:Skybox(snow):Up.jpg",
684                         ":Data:Textures:Skybox(snow):Down.jpg",
685                         ":Data:Textures:Skybox(snow):Cloud.jpg",
686                         ":Data:Textures:Skybox(snow):Reflect.jpg");
687
688
689
690
691                 texdetail=temptexdetail;
692         }
693         if(environment==desertenvironment){
694                 windvector=0;
695                 windvector.z=2;
696                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
697                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
698                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
699                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
700
701
702                 if(ambientsound){
703                         //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
704                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
705                         OPENAL_SetPaused(channels[stream_desertambient], false);
706                         OPENAL_SetVolume(channels[stream_desertambient], 256);
707                 }
708
709                 OPENAL_Sample_Free(samp[footstepsound]);
710                 OPENAL_Sample_Free(samp[footstepsound2]);
711                 OPENAL_Sample_Free(samp[footstepsound3]);
712                 OPENAL_Sample_Free(samp[footstepsound4]);
713                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
714                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
715                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
716                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
717                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
718                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
719                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
720                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
721
722                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
723
724                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
725
726                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
727
728
729
730                 temptexdetail=texdetail;
731                 if(texdetail>1)texdetail=4;
732                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
733                         ":Data:Textures:Skybox(sand):Left.jpg",
734                         ":Data:Textures:Skybox(sand):Back.jpg",
735                         ":Data:Textures:Skybox(sand):Right.jpg",
736                         ":Data:Textures:Skybox(sand):Up.jpg",
737                         ":Data:Textures:Skybox(sand):Down.jpg",
738                         ":Data:Textures:Skybox(sand):Cloud.jpg",
739                         ":Data:Textures:Skybox(sand):Reflect.jpg");
740
741
742
743
744                 texdetail=temptexdetail;
745         }
746         if(environment==grassyenvironment){
747                 windvector=0;
748                 windvector.z=2;
749                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
750                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
751                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
752                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
753
754                 if(ambientsound){
755                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
756                         OPENAL_SetPaused(channels[stream_wind], false);
757                         OPENAL_SetVolume(channels[stream_wind], 100);
758                 }
759
760                 OPENAL_Sample_Free(samp[footstepsound]);
761                 OPENAL_Sample_Free(samp[footstepsound2]);
762                 OPENAL_Sample_Free(samp[footstepsound3]);
763                 OPENAL_Sample_Free(samp[footstepsound4]);
764                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepgrass1.ogg", OPENAL_HW3D, 0, 0);
765                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepgrass2.ogg", OPENAL_HW3D, 0, 0);
766                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone1.ogg", OPENAL_HW3D, 0, 0);
767                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone2.ogg", OPENAL_HW3D, 0, 0);
768                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
769                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
770                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
771                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
772
773                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
774
775                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
776
777                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
778
779
780
781                 temptexdetail=texdetail;
782                 if(texdetail>1)texdetail=4;
783                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
784                         ":Data:Textures:Skybox(grass):Left.jpg",
785                         ":Data:Textures:Skybox(grass):Back.jpg",
786                         ":Data:Textures:Skybox(grass):Right.jpg",
787                         ":Data:Textures:Skybox(grass):Up.jpg",
788                         ":Data:Textures:Skybox(grass):Down.jpg",
789                         ":Data:Textures:Skybox(grass):Cloud.jpg",
790                         ":Data:Textures:Skybox(grass):Reflect.jpg");
791
792
793
794                 texdetail=temptexdetail;
795         }
796         temptexdetail=texdetail;
797         texdetail=1;
798         terrain.load(":Data:Textures:heightmap.png");
799
800         texdetail=temptexdetail;
801 }
802
803
804 void    Game::Loadlevel(int which){
805         stealthloading=0;
806
807         if(which==0)Loadlevel((char *)":Data:Maps:map1");
808         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
809         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
810         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
811         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
812         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
813         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
814         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
815         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
816         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
817         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
818         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
819         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
820         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
821         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
822         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
823         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
824         else Loadlevel((char *)":Data:Maps:mapsave");
825
826         whichlevel=which;
827 }
828
829 /*char * Game::MD5_string (unsigned char *string){
830 char temp[50];
831 char temp2[100];
832
833 strcpy(temp2,(const char *)string);
834 strcat((char *)temp2,(const char *)"Lugaru");
835 sprintf (temp, "%d",strlen((char *)temp2));
836 strcat((char *)temp2,temp);
837
838 MD5 context;
839 unsigned int len = strlen ( (char *)temp2);
840
841 context.update   ((unsigned char *)temp2, len);
842 context.finalize ();
843
844 return context.hex_digest();
845 }*/
846
847
848
849 void    Game::Loadlevel(char *name){
850         int i,j,k,l,m;
851         static int oldlevel;
852         int templength;
853         float lamefloat;
854         int lameint;
855
856         float headprop,legprop,armprop,bodyprop;
857
858         LOGFUNC;
859
860         LOG(std::string("Loading level...") + name);
861
862         if(!gameon)visibleloading=1;
863
864         if(stealthloading)visibleloading=0;
865
866         if(!stillloading)loadtime=0;
867         gamestarted=1;
868
869         numenvsounds=0;
870         //visibleloading=1;
871         if(tutoriallevel!=-1)tutoriallevel=0;
872         else tutoriallevel=1;
873
874         if(tutoriallevel==1)tutorialstage=0;
875         if(tutorialstage==0){
876                 tutorialstagetime=0;
877                 tutorialmaxtime=1;
878         }
879         loadingstuff=1;
880         if(!firstload){
881                 oldlevel=50;
882         }
883         OPENAL_SetPaused(channels[whooshsound], true);
884         OPENAL_SetPaused(channels[stream_firesound], true);
885
886         // Change the map filename into something that is os specific
887         char *FixedFN = ConvertFileName(name);
888
889         int mapvers;
890         FILE                    *tfile;
891         tfile=fopen( FixedFN, "rb" );
892         if(tfile)
893         {
894                 OPENAL_SetPaused(channels[stream_firesound], true);
895
896
897                 scoreadded=0;
898                 windialogue=0;
899
900                 hostiletime=0;
901
902                 won=0;
903
904                 //campaign=0;
905                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
906
907                 numdialogues=0;
908
909                 for(i=0;i<20;i++)
910                 {
911                         dialoguegonethrough[i]=0;
912                 }
913
914                 indialogue=-1;
915                 cameramode=0;
916
917                 damagedealt=0;
918                 damagetaken=0;
919
920                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
921
922                 if(difficulty!=2)minimap=1;
923                 else minimap=0;
924
925                 numhotspots=0;
926                 currenthotspot=-1;
927                 bonustime=1;
928
929                 skyboxtexture=1;
930                 skyboxr=1;
931                 skyboxg=1;
932                 skyboxb=1;
933
934                 freeze=0;
935                 winfreeze=0;
936
937                 for(i=0;i<100;i++)
938                 {
939                         bonusnum[i]=0;
940                 }
941
942                 numfalls=0;
943                 numflipfail=0;
944                 numseen=0;
945                 numstaffattack=0;
946                 numswordattack=0;
947                 numknifeattack=0;
948                 numunarmedattack=0;
949                 numescaped=0;
950                 numflipped=0;
951                 numwallflipped=0;
952                 numthrowkill=0;
953                 numafterkill=0;
954                 numreversals=0;
955                 numattacks=0;
956                 maxalarmed=0;
957                 numresponded=0;
958
959                 bonustotal=startbonustotal;
960                 bonus=0;
961                 gameon=1;
962                 changedelay=0;
963                 if(console)
964                 {
965                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
966                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
967                         OPENAL_SetPaused(channels[consolesuccesssound], false);
968                         freeze=0;
969                         console=0;
970                 }
971
972                 if(!stealthloading)
973                 {
974                         terrain.numdecals=0;
975                         sprites.numsprites=0;
976                         for(i=0;i<objects.numobjects;i++)
977                         {
978                                 objects.model[i].numdecals=0;
979                         }
980
981                         j=objects.numobjects;
982                         for(i=0;i<j;i++)
983                         {
984                                 objects.DeleteObject(0);
985                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
986                         }
987
988                         for(i=0;i<subdivision;i++)
989                         {
990                                 for(j=0;j<subdivision;j++)
991                                 {
992                                         terrain.patchobjectnum[i][j]=0;
993                                 }
994                         }
995                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
996                 }
997
998                 weapons.numweapons=0;
999
1000                 funpackf(tfile, "Bi", &mapvers);
1001                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
1002                 else indemo=0;
1003                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1004                 else maptype=mapkilleveryone;
1005                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1006                 else hostile=1;
1007                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1008                 else
1009                 {
1010                         viewdistance=100;
1011                         fadestart=.6;
1012                 }
1013                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1014                 else
1015                 {
1016                         skyboxtexture=1;
1017                         skyboxr=1;
1018                         skyboxg=1;
1019                         skyboxb=1;
1020                 }
1021                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1022                 else
1023                 {
1024                         skyboxlightr=skyboxr;
1025                         skyboxlightg=skyboxg;
1026                         skyboxlightb=skyboxb;
1027                 }
1028                 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);
1029                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1030                 player[0].originalcoords=player[0].coords;
1031                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1032                 {
1033                         for(j=0;j<player[0].num_weapons;j++)
1034                         {
1035                                 player[0].weaponids[j]=weapons.numweapons;
1036                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1037                                 weapons.owner[weapons.numweapons]=0;
1038                                 weapons.numweapons++;
1039                         }
1040                 }
1041
1042                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1043
1044                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1045                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1046                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1047                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1048
1049                 funpackf(tfile, "Bi", &player[0].numclothes);
1050
1051                 if(mapvers>=9)
1052                 {
1053                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1054                 }
1055                 else
1056                 {
1057                         player[0].whichskin=0;
1058                         player[0].creature=rabbittype;
1059                 }
1060
1061                 for(i=0;i<max_dialogues;i++)
1062                 {
1063                         for(j=0;j<max_dialoguelength;j++)
1064                         {
1065                                 for(k=0;k<128;k++)
1066                                 {
1067                                         dialoguetext[i][j][k]='\0';
1068                                 }
1069                                 for(k=0;k<64;k++)
1070                                 {
1071                                         dialoguename[i][j][k]='\0';
1072                                 }
1073                         }
1074                 }
1075
1076                 player[0].lastattack=-1;
1077                 player[0].lastattack2=-1;
1078                 player[0].lastattack3=-1;
1079
1080                 if(mapvers>=8)
1081                 {
1082                         funpackf(tfile, "Bi", &numdialogues);
1083                         if(numdialogues)
1084                         {
1085                                 for(k=0;k<numdialogues;k++)
1086                                 {
1087                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1088                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1089                                         for(l=0;l<10;l++)
1090                                         {
1091                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1092                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1093                                         }
1094                                         if(numdialogueboxes)
1095                                         {
1096                                                 for(l=0;l<numdialogueboxes[k];l++)
1097                                                 {
1098                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1099                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1100                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1101                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1102                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1103
1104                                                         bool doneread;
1105
1106                                                         funpackf(tfile, "Bi",&templength);
1107                                                         if(templength>128||templength<=0)templength=128;
1108                                                         for(m=0;m<templength;m++){
1109                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1110                                                                 if(dialoguetext[k][l][m]=='\0')break;
1111                                                         }
1112
1113                                                         funpackf(tfile, "Bi",&templength);
1114                                                         if(templength>64||templength<=0)templength=64;
1115                                                         for(m=0;m<templength;m++){
1116                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1117                                                                 if(dialoguename[k][l][m]=='\0'){
1118                                                                         break;
1119                                                                 }
1120                                                         }
1121                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1122                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1123                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1124
1125                                                         for(m=0;m<10;m++)
1126                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1127
1128                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1129                                                 }
1130                                         }
1131                                 }
1132                         }
1133                 }
1134                 else numdialogues=0;
1135
1136                 if(player[0].numclothes)
1137                 {
1138                         for(k=0;k<player[0].numclothes;k++)
1139                         {
1140                                 funpackf(tfile, "Bi", &templength);
1141                                 for(l=0;l<templength;l++)
1142                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1143                                 player[0].clothes[k][templength]='\0';
1144                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1145                         }
1146                 }
1147
1148                 funpackf(tfile, "Bi", &environment);
1149
1150                 funpackf(tfile, "Bi", &objects.numobjects);
1151                 if(objects.numobjects)
1152                 {
1153                         for(i=0;i<objects.numobjects;i++)
1154                         {
1155                                 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]);
1156                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1157                         }
1158                 }
1159
1160                 if(mapvers>=7)
1161                 {
1162                         funpackf(tfile, "Bi", &numhotspots);
1163                         if(numhotspots)
1164                         {
1165                                 for(i=0;i<numhotspots;i++)
1166                                 {
1167                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1168                                         funpackf(tfile, "Bi", &templength);
1169                                         if(templength)
1170                                                 for(l=0;l<templength;l++)
1171                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1172                                         hotspottext[i][templength]='\0';
1173                                         if(hotspottype[i]==-111)indemo=1;
1174                                 }
1175                         }
1176                 }
1177                 else numhotspots=0;
1178
1179                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1180
1181                 if(!stealthloading)
1182                 {
1183                         objects.center=0;
1184                         for(i=0;i<objects.numobjects;i++)
1185                         {
1186                                 objects.center+=objects.position[i];
1187                         }
1188                         objects.center/=objects.numobjects;
1189
1190
1191                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1192
1193                         float maxdistance=0;
1194                         float tempdist;
1195                         int whichclosest;
1196                         for(i=0;i<objects.numobjects;i++)
1197                         {
1198                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1199                                 if(tempdist>maxdistance)
1200                                 {
1201                                         whichclosest=i;
1202                                         maxdistance=tempdist;
1203                                 }
1204                         }
1205                         objects.radius=fast_sqrt(maxdistance);
1206                 }
1207
1208                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1209                 //mapcenter=objects.center;
1210                 //mapradius=objects.radius;
1211
1212                 funpackf(tfile, "Bi", &numplayers);
1213                 int howmanyremoved=0;
1214                 bool removeanother=0;
1215                 if(numplayers>1&&numplayers<maxplayers)
1216                 {
1217                         for(i=1;i<numplayers;i++)
1218                         {
1219                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1220                                 removeanother=0;
1221
1222                                 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);
1223                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1224                                 else player[i-howmanyremoved].howactive=typeactive;
1225                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1226                                 else player[i-howmanyremoved].scale=-1;
1227                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1228                                 else player[i-howmanyremoved].immobile=0;
1229                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1230                                 else player[i-howmanyremoved].rotation=0;
1231                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1232                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1233                                         removeanother=1;
1234                                         howmanyremoved++;
1235                                 }
1236                                 if(!removeanother)
1237                                 {
1238                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1239                                         {
1240                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1241                                                 {
1242                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1243                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1244                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1245                                                         weapons.numweapons++;
1246                                                 }
1247                                         }
1248                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1249                                         //player[i-howmanyremoved].numwaypoints=10;
1250                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1251                                         {
1252                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1253                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1254                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1255                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1256                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1257                                         }
1258
1259                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1260                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1261
1262                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1263                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1264                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1265                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1266
1267                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1268                                         else
1269                                         {
1270                                                 headprop=1;
1271                                                 bodyprop=1;
1272                                                 armprop=1;
1273                                                 legprop=1;
1274                                         }
1275                                         if(player[i-howmanyremoved].creature==wolftype)
1276                                         {
1277                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1278                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1279                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1280                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1281                                         }
1282
1283                                         if(player[i-howmanyremoved].creature==rabbittype)
1284                                         {
1285                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1286                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1287                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1288                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1289                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1290                                         }
1291
1292                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1293                                         if(player[i-howmanyremoved].numclothes)
1294                                         {
1295                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1296                                                 {
1297                                                         int templength;
1298                                                         funpackf(tfile, "Bi", &templength);
1299                                                         for(l=0;l<templength;l++)
1300                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1301                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1302                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1303                                                 }
1304                                         }
1305                                 }
1306                         }
1307                 }
1308                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1309
1310                 numplayers-=howmanyremoved;
1311                 funpackf(tfile, "Bi", &numpathpoints);
1312                 if(numpathpoints>30||numpathpoints<0)
1313                         numpathpoints=0;
1314                 if(numpathpoints)
1315                 {
1316                         for(j=0;j<numpathpoints;j++)
1317                         {
1318                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1319                                 for(k=0;k<numpathpointconnect[j];k++){
1320                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1321                                 }
1322                         }
1323                 }
1324                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1325
1326                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1327
1328                 SetUpLighting();
1329                 if(environment!=oldenvironment)Setenvironment(environment);
1330                 oldenvironment=environment;
1331
1332                 if(!stealthloading)
1333                 {
1334                         j=objects.numobjects;
1335                         objects.numobjects=0;
1336                         for(i=0;i<j;i++)
1337                         {
1338                                 //if(objects.type[i]!=spiketype)
1339                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1340                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1341                         }
1342
1343                         //if(skyboxtexture){
1344                         terrain.DoShadows();
1345                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1346                         objects.DoShadows();
1347                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1348                         /*}
1349                         else terrain.DoLighting();
1350                         */
1351                 }
1352
1353                 fclose(tfile);
1354
1355                 oldlevel=whichlevel;
1356
1357
1358                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1359                 for(i=0;i<numplayers;i++)
1360                 {
1361                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1362                         player[i].burnt=0;
1363                         player[i].bled=0;
1364                         player[i].onfire=0;
1365                         if(i==0||player[i].scale<0)player[i].scale=.2;
1366                         player[i].skeleton.free=0;
1367                         player[i].skeleton.id=i;
1368                         //if(Random()%2==0)player[i].creature=wolftype;
1369                         //else player[i].creature=rabbittype;
1370                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1371                         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);
1372                         else
1373                         {
1374                                 if(player[i].creature!=wolftype){
1375                                         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);
1376                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1377                                 }
1378                                 if(player[i].creature==wolftype){
1379                                         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);
1380                                 }
1381                         }
1382
1383
1384                         int texsize;
1385                         texsize=512*512*3/texdetail/texdetail;
1386                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1387                         //player[i].skeleton.skinText.resize(texsize);
1388
1389                         if(player[i].creature==rabbittype)
1390                         {
1391                                 if(player[i].whichskin==0){
1392                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1393                                 }
1394                                 else if(player[i].whichskin==1){
1395                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1396                                 }
1397                                 else if(player[i].whichskin==2){
1398                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1399                                 }
1400                                 else if(player[i].whichskin==3){
1401                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1402                                 }
1403                                 else if(player[i].whichskin==4){
1404                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1405                                 }
1406                                 else if(player[i].whichskin==5){
1407                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1408                                 }
1409                                 else if(player[i].whichskin==6){
1410                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1411                                 }
1412                                 else if(player[i].whichskin==7){
1413                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1414                                 }
1415                                 else if(player[i].whichskin==8){
1416                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1417                                 }
1418                                 else if(player[i].whichskin==9){
1419                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1420                                 }
1421                         }
1422                         if(player[i].creature==wolftype)
1423                         {
1424                                 //k=abs(Random()%3);
1425                                 if(player[i].whichskin==0){
1426                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1427                                 }
1428                                 else if(player[i].whichskin==1){
1429                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1430                                 }
1431                                 else if(player[i].whichskin==2){
1432                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1433                                 }
1434                         }
1435
1436                         if(player[i].numclothes)
1437                         {
1438                                 for(j=0;j<player[i].numclothes;j++)
1439                                 {
1440                                         tintr=player[i].clothestintr[j];
1441                                         tintg=player[i].clothestintg[j];
1442                                         tintb=player[i].clothestintb[j];
1443                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1444                                 }
1445                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1446                         }
1447
1448                         player[i].currentanimation=bounceidleanim;
1449                         player[i].targetanimation=bounceidleanim;
1450                         player[i].currentframe=0;
1451                         player[i].targetframe=1;
1452                         player[i].target=0;
1453                         player[i].speed=1+(float)(Random()%100)/1000;
1454                         if(difficulty==0)player[i].speed-=.2;
1455                         if(difficulty==1)player[i].speed-=.1;
1456
1457                         player[i].velocity=0;
1458                         player[i].oldcoords=player[i].coords;
1459                         player[i].realoldcoords=player[i].coords;
1460
1461                         player[i].id=i;
1462                         player[i].skeleton.id=i;
1463                         player[i].updatedelay=0;
1464                         player[i].normalsupdatedelay=0;
1465
1466                         player[i].aitype=passivetype;
1467                         player[i].aitarget=0;
1468                         player[i].madskills=0;
1469
1470                         if(i==0)
1471                         {
1472                                 player[i].proportionhead=1.2;
1473                                 player[i].proportionbody=1.05;
1474                                 player[i].proportionarms=1.00;
1475                                 player[i].proportionlegs=1.1;
1476                                 player[i].proportionlegs.y=1.05;
1477                         }
1478                         player[i].headless=0;
1479                         player[i].currentoffset=0;
1480                         player[i].targetoffset=0;
1481                         /*player[i].armorhead=1;
1482                         player[i].armorhigh=1;
1483                         player[i].armorlow=1;
1484                         player[i].protectionhead=1;
1485                         player[i].protectionhigh=1;
1486                         player[i].protectionlow=1;
1487                         player[i].metalhead=1;
1488                         player[i].metalhigh=1;
1489                         player[i].metallow=1;
1490                         player[i].power=1;
1491                         player[i].speedmult=1;*/
1492
1493                         player[i].damagetolerance=200;
1494
1495                         if(player[i].creature==wolftype)
1496                         {
1497                                 /*player[i].proportionhead=1.1;
1498                                 player[i].proportionbody=1.1;
1499                                 player[i].proportionarms=1.1;
1500                                 player[i].proportionlegs=1.1;
1501                                 player[i].proportionlegs.y=1.1;*/
1502                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1503
1504                                 player[i].damagetolerance=300;
1505                         }
1506
1507                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1508                         if(cellophane)
1509                         {
1510                                 player[i].proportionhead.z=0;
1511                                 player[i].proportionbody.z=0;
1512                                 player[i].proportionarms.z=0;
1513                                 player[i].proportionlegs.z=0;
1514                         }
1515
1516                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1517
1518                         player[i].headmorphness=0;
1519                         player[i].targetheadmorphness=1;
1520                         player[i].headmorphstart=0;
1521                         player[i].headmorphend=0;
1522
1523                         player[i].pausetime=0;
1524
1525                         player[i].dead=0;
1526                         player[i].jumppower=5;
1527                         player[i].damage=0;
1528                         player[i].permanentdamage=0;
1529                         player[i].superpermanentdamage=0;
1530
1531                         player[i].forwardkeydown=0;
1532                         player[i].leftkeydown=0;
1533                         player[i].backkeydown=0;
1534                         player[i].rightkeydown=0;
1535                         player[i].jumpkeydown=0;
1536                         player[i].crouchkeydown=0;
1537                         player[i].throwkeydown=0;
1538
1539                         player[i].collided=-10;
1540                         player[i].loaded=1;
1541                         player[i].bloodloss=0;
1542                         player[i].weaponactive=-1;
1543                         player[i].weaponstuck=-1;
1544                         player[i].bleeding=0;
1545                         player[i].deathbleeding=0;
1546                         player[i].stunned=0;
1547                         player[i].hasvictim=0;
1548                         player[i].wentforweapon=0;
1549                 }
1550
1551                 player[0].aitype=playercontrolled;
1552                 player[0].weaponactive=-1;
1553
1554                 if(difficulty==1)
1555                 {
1556                         //player[0].speedmult=1/.9;
1557                         player[0].power=1/.9;
1558                 }
1559
1560                 if(difficulty==0)
1561                 {
1562                         //player[0].speedmult=1/.8;
1563                         player[0].power=1/.8;
1564                 }
1565
1566                 //player[0].weaponstuck=1;
1567
1568                 if(difficulty==1)player[0].damagetolerance=250;
1569                 if(difficulty==0)player[0].damagetolerance=300;
1570                 if(difficulty==0)player[0].armorhead*=1.5;
1571                 if(difficulty==0)player[0].armorhigh*=1.5;
1572                 if(difficulty==0)player[0].armorlow*=1.5;
1573                 cameraloc=player[0].coords;
1574                 cameraloc.y+=5;
1575                 rotation=player[0].rotation;
1576
1577                 hawkcoords=player[0].coords;
1578                 hawkcoords.y+=30;
1579
1580                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1581                 //weapons.numweapons=numplayers;
1582                 for(i=0;i<weapons.numweapons;i++)
1583                 {
1584                         weapons.bloody[i]=0;
1585                         weapons.blooddrip[i]=0;
1586                         weapons.blooddripdelay[i]=0;
1587                         weapons.onfire[i]=0;
1588                         weapons.flamedelay[i]=0;
1589                         weapons.damage[i]=0;
1590                         //weapons.type[i]=sword;
1591                         if(weapons.type[i]==sword){
1592                                 weapons.mass[i]=1.5;
1593                                 weapons.tipmass[i]=1;
1594                                 weapons.length[i]=.8;
1595                         }
1596                         if(weapons.type[i]==staff){
1597                                 weapons.mass[i]=2;
1598                                 weapons.tipmass[i]=1;
1599                                 weapons.length[i]=1.5;
1600                         }
1601                         if(weapons.type[i]==knife){
1602                                 weapons.mass[i]=1;
1603                                 weapons.tipmass[i]=1.2;
1604                                 weapons.length[i]=.25;
1605                         }
1606                         weapons.position[i]=-1000;
1607                         weapons.tippoint[i]=-1000;
1608                 }
1609
1610 /*              for(i=0;i<32;i++){
1611                         //if(i<16||i>20)
1612                         OPENAL_StopSound(i);
1613                 }
1614 */
1615                 LOG("Starting background music...");
1616
1617                 OPENAL_StopSound(OPENAL_ALL);
1618                 if(environment==snowyenvironment)
1619                 {
1620                         if(ambientsound)
1621                         {
1622                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1623                                 OPENAL_SetPaused(channels[stream_wind], false);
1624                                 OPENAL_SetVolume(channels[stream_wind], 256);
1625                         }
1626                 }
1627                 else if(environment==desertenvironment)
1628                 {
1629                         if(ambientsound)
1630                         {
1631                                 //PlaySoundEx(desertambient,
1632                                 //      samp[desertambient], NULL, true);
1633                                 PlayStreamEx(stream_desertambient,
1634                                         strm[stream_desertambient], NULL, true);
1635                                 OPENAL_SetPaused(channels[stream_desertambient], false);
1636                                 OPENAL_SetVolume(channels[stream_desertambient], 256);
1637                         }
1638                 }
1639                 else if(environment==grassyenvironment)
1640                 {
1641                         if(ambientsound)
1642                         {
1643                                 //PlaySoundEx(wind, samp[wind], NULL, true);
1644                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1645                                 OPENAL_SetPaused(channels[stream_wind], false);
1646                                 OPENAL_SetVolume(channels[stream_wind], 100);
1647                         }
1648                 }
1649                 oldmusicvolume[0]=0;
1650                 oldmusicvolume[1]=0;
1651                 oldmusicvolume[2]=0;
1652                 oldmusicvolume[3]=0;
1653
1654
1655                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1656                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1657                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1658                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1659                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1660                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1661                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1662                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1663                 */
1664
1665                 if(!firstload)
1666                 {
1667                         firstload=1;
1668                 }
1669         }
1670         leveltime=0;
1671         loadingstuff=0;
1672         visibleloading=0;
1673 }
1674
1675 void    Game::Tick()
1676 {
1677         static int i,k,j,l,m;
1678         static XYZ facing,flatfacing,absflatfacing;
1679         static XYZ rotatetarget;
1680         static bool oldkey;
1681         static float oldtargetrotation;
1682         static int target, numgood;
1683         static XYZ tempcoords1,tempcoords2;
1684         static XYZ test;
1685         static XYZ test2;
1686         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1687         static int whichhit;
1688         static bool donesomething;
1689         static bool oldjumpkeydown;
1690
1691         int templength;
1692
1693         float headprop,bodyprop,armprop,legprop;
1694
1695         for(i=0;i<15;i++){
1696                 displaytime[i]+=multiplier;
1697         }
1698
1699         static unsigned char    theKeyMap[16];
1700         GetKeys( theKeyMap );
1701
1702         keyboardfrozen=0;
1703
1704
1705         static bool mainmenutogglekeydown;
1706         if(!console){
1707                 if(mainmenu&&endgame==1)mainmenu=10;
1708                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1709                         for(j=0;j<255;j++){
1710                                 displaytext[0][j]=' ';
1711                         }
1712                         displaychars[0]=0;
1713                         displayselected=0;
1714                         entername=0;
1715                         mainmenutogglekeydown=1;
1716                 }
1717                 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)){
1718                         selected=-1;
1719                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1720                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1721                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1722                                 else if(mainmenu==0&&winfreeze){
1723                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1724                                         stealthloading=1;
1725                                         else stealthloading=0;
1726
1727                                         if(!stealthloading){
1728                                         float gLoc[3]={0,0,0};
1729                                         float vel[3]={0,0,0};
1730                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1731                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1732                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1733                                         OPENAL_SetVolume(channels[firestartsound], 256);
1734                                         OPENAL_SetPaused(channels[firestartsound], false);
1735                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1736
1737                                         flashr=1;
1738                                         flashg=0;
1739                                         flashb=0;
1740                                         flashamount=1;
1741                                         flashdelay=1;
1742                                         }
1743
1744                                         startbonustotal=0;
1745
1746                                         for(i=0;i<campaignnumlevels;i++){
1747                                         levelvisible[i]=0;
1748                                         levelhighlight[i]=0;
1749                                         }
1750
1751                                         levelorder[0]=0;
1752                                         levelvisible[0]=1;
1753                                         if(accountcampaignchoicesmade[accountactive])
1754                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1755                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1756                                         levelvisible[levelorder[i+1]]=1;
1757                                         }
1758                                         int whichlevelstart;
1759                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1760                                         if(whichlevelstart<0){
1761                                         campaignchoicenum=1;
1762                                         campaignchoicewhich[0]=0;
1763                                         }
1764                                         else
1765                                         {
1766                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1767                                         if(campaignchoicenum)
1768                                         for(i=0;i<campaignchoicenum;i++){
1769                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1770                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1771                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1772                                         }
1773                                         }
1774
1775                                         loading=2;
1776                                         loadtime=0;
1777                                         targetlevel=7;
1778                                         if(firstload)TickOnceAfter();
1779                                         if(!firstload)LoadStuff();
1780                                         //else {
1781                                         for(i=0;i<255;i++){
1782                                         mapname[i]='\0';
1783                                         }
1784                                         mapname[0]=':';
1785                                         mapname[1]='D';
1786                                         mapname[2]='a';
1787                                         mapname[3]='t';
1788                                         mapname[4]='a';
1789                                         mapname[5]=':';
1790                                         mapname[6]='M';
1791                                         mapname[7]='a';
1792                                         mapname[8]='p';
1793                                         mapname[9]='s';
1794                                         mapname[10]=':';
1795
1796                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1797                                         //accountcampaignchoicesmade[accountactive]++;
1798
1799
1800                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1801                                         whichchoice=0;
1802                                         visibleloading=1;
1803                                         stillloading=1;
1804                                         Loadlevel(mapname);
1805                                         campaign=1;
1806                                         mainmenu=0;
1807                                         gameon=1;
1808                                         OPENAL_SetPaused(channels[music3], true);
1809
1810                                         stealthloading=0;*/
1811                                 }
1812                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1813                                 if(mainmenu&&musictoggle){
1814                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1815                                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
1816                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
1817                                                 OPENAL_SetPaused(channels[stream_music3], false);
1818                                                 OPENAL_SetVolume(channels[stream_music3], 256);
1819                                                 OPENAL_SetPaused(channels[music1], true);
1820                                         }
1821                                 }
1822                                 if(!mainmenu){
1823                                         OPENAL_SetPaused(channels[stream_music3], true);
1824                                         OPENAL_SetPaused(channels[music1], false);
1825                                 }
1826                         }
1827                         if(mainmenu==3){
1828                                 float gLoc[3]={0,0,0};
1829                                 float vel[3]={0,0,0};
1830                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1831                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1832                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1833                                 OPENAL_SetVolume(channels[fireendsound], 256);
1834                                 OPENAL_SetPaused(channels[fireendsound], false);
1835                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1836
1837                                 flashr=1;
1838                                 flashg=0;
1839                                 flashb=0;
1840                                 flashamount=1;
1841                                 flashdelay=1;
1842
1843                                 if(newdetail>2)newdetail=detail;
1844                                 if(newdetail<0)newdetail=detail;
1845                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1846                                 if(newscreenheight<0)newscreenheight=screenheight;
1847
1848                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
1849                                 opstream << "Screenwidth:\n";
1850                                 opstream << newscreenwidth;
1851                                 opstream << "\nScreenheight:\n";
1852                                 opstream << newscreenheight;
1853                                 opstream << "\nMouse sensitivity:\n";
1854                                 opstream << usermousesensitivity;
1855                                 opstream << "\nBlur(0,1):\n";
1856                                 opstream << ismotionblur;
1857                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1858                                 opstream << newdetail;
1859                                 opstream << "\nFloating jump:\n";
1860                                 opstream << floatjump;
1861                                 opstream << "\nMouse jump:\n";
1862                                 opstream << mousejump;
1863                                 opstream << "\nAmbient sound:\n";
1864                                 opstream << ambientsound;
1865                                 opstream << "\nBlood (0,1,2):\n";
1866                                 opstream << bloodtoggle;
1867                                 opstream << "\nAuto slomo:\n";
1868                                 opstream << autoslomo;
1869                                 opstream << "\nFoliage:\n";
1870                                 opstream << foliage;
1871                                 opstream << "\nMusic:\n";
1872                                 opstream << musictoggle;
1873                                 opstream << "\nTrilinear:\n";
1874                                 opstream << trilinear;
1875                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1876                                 opstream << decals;
1877                                 opstream << "\nInvert mouse:\n";
1878                                 opstream << invertmouse;
1879                                 opstream << "\nGamespeed:\n";
1880                                 if(oldgamespeed==0)oldgamespeed=1;
1881                                 opstream << oldgamespeed;
1882                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1883                                 opstream << difficulty;
1884                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1885                                 opstream << damageeffects;
1886                                 opstream << "\nText:\n";
1887                                 opstream << texttoggle;
1888                                 opstream << "\nDebug:\n";
1889                                 opstream << debugmode;
1890                                 opstream << "\nVBL Sync:\n";
1891                                 opstream << vblsync;
1892                                 opstream << "\nShow Points:\n";
1893                                 opstream << showpoints;
1894                                 opstream << "\nAlways Blur:\n";
1895                                 opstream << alwaysblur;
1896                                 opstream << "\nImmediate mode (turn on on G5):\n";
1897                                 opstream << immediate;
1898                                 opstream << "\nVelocity blur:\n";
1899                                 opstream << velocityblur;
1900                             opstream << "\nVolume:\n";
1901                         opstream << volume;
1902                                 opstream << "\nForward key:\n";
1903                                 opstream << KeyToChar(forwardkey);
1904                                 opstream << "\nBack key:\n";
1905                                 opstream << KeyToChar(backkey);
1906                                 opstream << "\nLeft key:\n";
1907                                 opstream << KeyToChar(leftkey);
1908                                 opstream << "\nRight key:\n";
1909                                 opstream << KeyToChar(rightkey);
1910                                 opstream << "\nJump key:\n";
1911                                 opstream << KeyToChar(jumpkey);
1912                                 opstream << "\nCrouch key:\n";
1913                                 opstream << KeyToChar(crouchkey);
1914                                 opstream << "\nDraw key:\n";
1915                                 opstream << KeyToChar(drawkey);
1916                                 opstream << "\nThrow key:\n";
1917                                 opstream << KeyToChar(throwkey);
1918                                 opstream << "\nAttack key:\n";
1919                                 opstream << KeyToChar(attackkey);
1920                                 opstream << "\nChat key:\n";
1921                                 opstream << KeyToChar(chatkey);
1922                                 opstream.close();
1923                         }
1924                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){
1925                                 float gLoc[3]={0,0,0};
1926                                 float vel[3]={0,0,0};
1927                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1928                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1929                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1930                                 OPENAL_SetVolume(channels[fireendsound], 256);
1931                                 OPENAL_SetPaused(channels[fireendsound], false);
1932                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1933
1934                                 flashr=1;
1935                                 flashg=0;
1936                                 flashb=0;
1937                                 flashamount=1;
1938                                 flashdelay=1;
1939                         }
1940                         if(mainmenu==3&&gameon)mainmenu=2;
1941                         if(mainmenu==3&&!gameon)mainmenu=1;
1942                         if(mainmenu==5&&gameon)mainmenu=2;
1943                         if(mainmenu==5&&!gameon)mainmenu=1;
1944                         if(mainmenu==4)mainmenu=3;
1945                         if(mainmenu==6)mainmenu=5;
1946                         if(mainmenu==7)mainmenu=1;
1947                         if(mainmenu==9)mainmenu=5;
1948                         if(mainmenu==11)mainmenu=5;
1949                         if(mainmenu==13)mainmenu=12;
1950                         if(mainmenu==10)mainmenu=5;
1951                         if(mainmenu==100){
1952                                 mainmenu=5;
1953                                 gameon=0;
1954                                 winfreeze=0;
1955                         }
1956                         mainmenutogglekeydown=1;
1957                 }
1958                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1959                         mainmenutogglekeydown=0;
1960                 }
1961         }
1962
1963         /*static bool minimaptogglekeydown;
1964         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1965         minimap=1-minimap;
1966         minimaptogglekeydown=1;
1967         }
1968         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1969         minimaptogglekeydown=0;
1970         }
1971         */
1972
1973         static bool minimaptogglekeydown;
1974         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
1975                 if(tutorialstage!=51)
1976                         tutorialstagetime=tutorialmaxtime;
1977                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
1978                 OPENAL_SetVolume(channels[consolefailsound], 128);
1979                 OPENAL_SetPaused(channels[consolefailsound], false);
1980                 minimaptogglekeydown=1;
1981         }
1982         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1983                 minimaptogglekeydown=0;
1984         }
1985
1986         if(mainmenu){
1987                 //menu buttons
1988                 if(mainmenu==1||mainmenu==2){
1989                         if(Button()&&!oldbutton&&selected==1){
1990                                 if(!gameon){
1991                                         float gLoc[3]={0,0,0};
1992                                         float vel[3]={0,0,0};
1993                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1994                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1995                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1996                                         OPENAL_SetVolume(channels[firestartsound], 256);
1997                                         OPENAL_SetPaused(channels[firestartsound], false);
1998                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1999
2000                                         flashr=1;
2001                                         flashg=0;
2002                                         flashb=0;
2003                                         flashamount=1;
2004                                         flashdelay=1;
2005
2006                                         //new game
2007                                         if(accountactive!=-1)mainmenu=5;
2008                                         else mainmenu=7;
2009                                         /*
2010                                         startbonustotal=0;
2011
2012                                         loading=2;
2013                                         loadtime=0;
2014                                         if(firstload)TickOnceAfter();
2015                                         if(!firstload)LoadStuff();
2016                                         else {
2017                                         Loadlevel(0);
2018                                         }
2019                                         mainmenu=0;
2020                                         gameon=1;
2021                                         OPENAL_SetPaused(channels[music3], true);       */
2022                                 }
2023                                 else
2024                                 {
2025                                         //resume
2026                                         mainmenu=0;
2027                                         OPENAL_SetPaused(channels[stream_music3], true);
2028                                         OPENAL_SetPaused(channels[music1], false);
2029                                 }
2030                         }
2031
2032                         if(Button()&&!oldbutton&&selected==2){
2033                                 float gLoc[3]={0,0,0};
2034                                 float vel[3]={0,0,0};
2035                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2036                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2037                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2038                                 OPENAL_SetVolume(channels[firestartsound], 256);
2039                                 OPENAL_SetPaused(channels[firestartsound], false);
2040                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2041
2042                                 flashr=1;
2043                                 flashg=0;
2044                                 flashb=0;
2045                                 flashamount=1;
2046                                 flashdelay=1;
2047
2048                                 //options
2049
2050                                 mainmenu=3;
2051
2052                                 if(newdetail>2)newdetail=detail;
2053                                 if(newdetail<0)newdetail=detail;
2054                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2055                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2056                                 if(newscreenheight>3000)newscreenheight=screenheight;
2057                                 if(newscreenheight<0)newscreenheight=screenheight;
2058                         }
2059
2060                         if(Button()&&!oldbutton&&selected==3){
2061                                 float gLoc[3]={0,0,0};
2062                                 float vel[3]={0,0,0};
2063                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2064                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2065                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2066                                 OPENAL_SetVolume(channels[fireendsound], 256);
2067                                 OPENAL_SetPaused(channels[fireendsound], false);
2068                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2069
2070                                 flashr=1;
2071                                 flashg=0;
2072                                 flashb=0;
2073                                 flashamount=1;
2074                                 flashdelay=1;
2075
2076                                 if(!gameon){
2077                                         //quit
2078                                         tryquit=1;
2079                                         OPENAL_SetPaused(channels[stream_music3], true);
2080                                 }
2081                                 else{
2082                                         //end game
2083                                         gameon=0;
2084                                         mainmenu=1;
2085                                 }
2086                         }
2087                         if(Button())oldbutton=1;
2088                         else oldbutton=0;
2089                 }
2090
2091                 if(mainmenu==3){
2092                         if(Button()&&!oldbutton&&selected!=-1){
2093                                 float gLoc[3]={0,0,0};
2094                                 float vel[3]={0,0,0};
2095                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2096                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2097                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2098                                 OPENAL_SetVolume(channels[firestartsound], 256);
2099                                 OPENAL_SetPaused(channels[firestartsound], false);
2100                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2101                         }
2102                         if(Button()&&!oldbutton&&selected==0){
2103                         
2104                                 extern SDL_Rect **resolutions;
2105                                 bool isCustomResolution = true;
2106                                 bool found = false;
2107                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2108                                 {
2109                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2110                                                 isCustomResolution = false;
2111
2112                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2113                                         {
2114                                                 i++;
2115                                                 if (resolutions[i] != NULL)
2116                                                 {
2117                                                         newscreenwidth = (int) resolutions[i]->w;
2118                                                         newscreenheight = (int) resolutions[i]->h;
2119                                                 }
2120                                                 else if (isCustomResolution)
2121                                                 {
2122                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2123                                                         {
2124                                                                 newscreenwidth = (int) resolutions[0]->w;
2125                                                                 newscreenheight = (int) resolutions[0]->h;
2126                                                         }
2127                                                         else
2128                                                         {
2129                                                                 newscreenwidth = screenwidth;
2130                                                                 newscreenheight = screenheight;
2131                                                         }
2132                                                 }
2133                                                 else
2134                                                 {
2135                                                         newscreenwidth = (int) resolutions[0]->w;
2136                                                         newscreenheight = (int) resolutions[0]->h;
2137                                                 }
2138                                                 found = true;
2139                                         }
2140                                 }
2141
2142                                 if (!found)
2143                                 {
2144                                         newscreenwidth = (int) resolutions[0]->w;
2145                                         newscreenheight = (int) resolutions[0]->h;
2146                                 }
2147
2148                                 
2149                         }
2150                         if(Button()&&!oldbutton&&selected==1){
2151                                 newdetail++;
2152                                 if(newdetail>2)newdetail=0;
2153                         }
2154                         if(Button()&&!oldbutton&&selected==2){
2155                                 bloodtoggle++;
2156                                 if(bloodtoggle>2)bloodtoggle=0;
2157                         }
2158                         if(Button()&&!oldbutton&&selected==3){
2159                                 difficulty++;
2160                                 if(difficulty>2)difficulty=0;
2161                         }
2162                         if(Button()&&!oldbutton&&selected==4){
2163                                 ismotionblur=1-ismotionblur;
2164                         }
2165                         if(Button()&&!oldbutton&&selected==5){
2166                                 decals=1-decals;
2167                         }
2168                         if(Button()&&!oldbutton&&selected==6){
2169                                 musictoggle=1-musictoggle;
2170
2171                                 if(!musictoggle){
2172                                         OPENAL_SetPaused(channels[music1], true);
2173                                         OPENAL_SetPaused(channels[stream_music2], true);
2174                                         OPENAL_SetPaused(channels[stream_music3], true);
2175
2176                                         for(i=0;i<4;i++){
2177                                                 oldmusicvolume[i]=0;
2178                                                 musicvolume[i]=0;
2179                                         }
2180                                 }
2181
2182                                 if(musictoggle){
2183                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2184                                         OPENAL_SetPaused(channels[stream_music3], false);
2185                                         OPENAL_SetVolume(channels[stream_music3], 256);
2186                                 }
2187                         }
2188                         if(Button()&&!oldbutton&&selected==9){
2189                                 invertmouse=1-invertmouse;
2190                         }
2191                         if(Button()&&!oldbutton&&selected==10){
2192                                 usermousesensitivity+=.2;
2193                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2194                         }
2195                         if(Button()&&!oldbutton&&selected==11){
2196                                 volume+=.1f;
2197                                 if(volume>1.0001f)volume=0;
2198                                 OPENAL_SetSFXMasterVolume((int)(volume*255));
2199                         }
2200                         if(Button()&&!oldbutton&&selected==7){
2201                                 /*float gLoc[3]={0,0,0};
2202                                 float vel[3]={0,0,0};
2203                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2204                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2205                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2206                                 OPENAL_SetVolume(channels[firestartsound], 256);
2207                                 OPENAL_SetPaused(channels[firestartsound], false);
2208                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2209                                 */
2210                                 flashr=1;
2211                                 flashg=0;
2212                                 flashb=0;
2213                                 flashamount=1;
2214                                 flashdelay=1;
2215
2216                                 //options
2217
2218                                 mainmenu=4;
2219                                 keyselect=-1;
2220                         }
2221                         if(Button()&&!oldbutton&&selected==8){
2222                                 float gLoc[3]={0,0,0};
2223                                 float vel[3]={0,0,0};
2224                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2225                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2226                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2227                                 OPENAL_SetVolume(channels[fireendsound], 256);
2228                                 OPENAL_SetPaused(channels[fireendsound], false);
2229                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2230
2231                                 flashr=1;
2232                                 flashg=0;
2233                                 flashb=0;
2234                                 flashamount=1;
2235                                 flashdelay=1;
2236
2237                                 if(newdetail>2)newdetail=detail;
2238                                 if(newdetail<0)newdetail=detail;
2239                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2240                                 if(newscreenheight<0)newscreenheight=screenheight;
2241
2242
2243                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2244                                 opstream << "Screenwidth:\n";
2245                                 opstream << newscreenwidth;
2246                                 opstream << "\nScreenheight:\n";
2247                                 opstream << newscreenheight;
2248                                 opstream << "\nMouse sensitivity:\n";
2249                                 opstream << usermousesensitivity;
2250                                 opstream << "\nBlur(0,1):\n";
2251                                 opstream << ismotionblur;
2252                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2253                                 opstream << newdetail;
2254                                 opstream << "\nFloating jump:\n";
2255                                 opstream << floatjump;
2256                                 opstream << "\nMouse jump:\n";
2257                                 opstream << mousejump;
2258                                 opstream << "\nAmbient sound:\n";
2259                                 opstream << ambientsound;
2260                                 opstream << "\nBlood (0,1,2):\n";
2261                                 opstream << bloodtoggle;
2262                                 opstream << "\nAuto slomo:\n";
2263                                 opstream << autoslomo;
2264                                 opstream << "\nFoliage:\n";
2265                                 opstream << foliage;
2266                                 opstream << "\nMusic:\n";
2267                                 opstream << musictoggle;
2268                                 opstream << "\nTrilinear:\n";
2269                                 opstream << trilinear;
2270                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2271                                 opstream << decals;
2272                                 opstream << "\nInvert mouse:\n";
2273                                 opstream << invertmouse;
2274                                 opstream << "\nGamespeed:\n";
2275                                 if(oldgamespeed==0)oldgamespeed=1;
2276                                 opstream << oldgamespeed;
2277                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2278                                 opstream << difficulty;
2279                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2280                                 opstream << damageeffects;
2281                                 opstream << "\nText:\n";
2282                                 opstream << texttoggle;
2283                                 opstream << "\nDebug:\n";
2284                                 opstream << debugmode;
2285                                 opstream << "\nVBL Sync:\n";
2286                                 opstream << vblsync;
2287                                 opstream << "\nShow Points:\n";
2288                                 opstream << showpoints;
2289                                 opstream << "\nAlways Blur:\n";
2290                                 opstream << alwaysblur;
2291                                 opstream << "\nImmediate mode (turn on on G5):\n";
2292                                 opstream << immediate;
2293                                 opstream << "\nVelocity blur:\n";
2294                                 opstream << velocityblur;
2295                             opstream << "\nVolume:\n";
2296                         opstream << volume;
2297                                 opstream << "\nForward key:\n";
2298                                 opstream << KeyToChar(forwardkey);
2299                                 opstream << "\nBack key:\n";
2300                                 opstream << KeyToChar(backkey);
2301                                 opstream << "\nLeft key:\n";
2302                                 opstream << KeyToChar(leftkey);
2303                                 opstream << "\nRight key:\n";
2304                                 opstream << KeyToChar(rightkey);
2305                                 opstream << "\nJump key:\n";
2306                                 opstream << KeyToChar(jumpkey);
2307                                 opstream << "\nCrouch key:\n";
2308                                 opstream << KeyToChar(crouchkey);
2309                                 opstream << "\nDraw key:\n";
2310                                 opstream << KeyToChar(drawkey);
2311                                 opstream << "\nThrow key:\n";
2312                                 opstream << KeyToChar(throwkey);
2313                                 opstream << "\nAttack key:\n";
2314                                 opstream << KeyToChar(attackkey);
2315                                 opstream << "\nChat key:\n";
2316                                 opstream << KeyToChar(chatkey);
2317                                 opstream.close();
2318
2319                                 if(mainmenu==3&&gameon)mainmenu=2;
2320                                 if(mainmenu==3&&!gameon)mainmenu=1;
2321                         }
2322                         if(Button())oldbutton=1;
2323                         else oldbutton=0;
2324                 }
2325                 if(mainmenu==4){
2326                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2327                                 float gLoc[3]={0,0,0};
2328                                 float vel[3]={0,0,0};
2329                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2330                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2331                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2332                                 OPENAL_SetVolume(channels[firestartsound], 256);
2333                                 OPENAL_SetPaused(channels[firestartsound], false);
2334                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2335                         }
2336                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2337                                 keyselect=selected;
2338                                 oldbuttons[0]=1;
2339                                 oldbuttons[1]=1;
2340                                 oldbuttons[2]=1;
2341                         }
2342                         if(keyselect!=-1){
2343                                 for(i=0;i<3;i++)
2344                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2345                                 for(i=0;i<140;i++){
2346                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2347                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2348                                                         float gLoc[3]={0,0,0};
2349                                                         float vel[3]={0,0,0};
2350                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2351                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2352                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2353                                                         OPENAL_SetVolume(channels[fireendsound], 256);
2354                                                         OPENAL_SetPaused(channels[fireendsound], false);
2355                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2356
2357                                                         int keynum;
2358                                                         keynum=i;
2359                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2360                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2361
2362
2363
2364                                                         if(keyselect==0)forwardkey=keynum;
2365                                                         if(keyselect==1)backkey=keynum;
2366                                                         if(keyselect==2)leftkey=keynum;
2367                                                         if(keyselect==3)rightkey=keynum;
2368                                                         if(keyselect==4)crouchkey=keynum;
2369                                                         if(keyselect==5)jumpkey=keynum;
2370                                                         if(keyselect==6)drawkey=keynum;
2371                                                         if(keyselect==7)throwkey=keynum;
2372                                                         if(keyselect==8)attackkey=keynum;
2373                                                         keyselect=-1;
2374                                                 }
2375                                         }
2376                                 }}
2377                         if(Button()&&!oldbutton&&selected==9){
2378                                 float gLoc[3]={0,0,0};
2379                                 float vel[3]={0,0,0};
2380                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2381                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2382                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2383                                 OPENAL_SetVolume(channels[fireendsound], 256);
2384                                 OPENAL_SetPaused(channels[fireendsound], false);
2385                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2386
2387                                 flashr=1;
2388                                 flashg=0;
2389                                 flashb=0;
2390                                 flashamount=1;
2391                                 flashdelay=1;
2392
2393                                 mainmenu=3;
2394
2395                                 if(newdetail>2)newdetail=detail;
2396                                 if(newdetail<0)newdetail=detail;
2397                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2398                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2399                                 if(newscreenheight>3000)newscreenheight=screenheight;
2400                                 if(newscreenheight<0)newscreenheight=screenheight;
2401                         }
2402                 }
2403
2404                 if(mainmenu==5){
2405
2406                         if(endgame==2){
2407                                 accountcampaignchoicesmade[accountactive]=0;
2408                                 accountcampaignscore[accountactive]=0;
2409                                 accountcampaigntime[accountactive]=0;
2410                                 endgame=0;
2411                         }
2412
2413                         if(Button()&&!oldbutton&&selected==1){
2414                                 float gLoc[3]={0,0,0};
2415                                 float vel[3]={0,0,0};
2416                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2417                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2418                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2419                                 OPENAL_SetVolume(channels[firestartsound], 256);
2420                                 OPENAL_SetPaused(channels[firestartsound], false);
2421                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2422
2423                                 flashr=1;
2424                                 flashg=0;
2425                                 flashb=0;
2426                                 flashamount=1;
2427                                 flashdelay=1;
2428
2429                                 startbonustotal=0;
2430
2431                                 loading=2;
2432                                 loadtime=0;
2433                                 targetlevel=-1;
2434                                 if(firstload)TickOnceAfter();
2435                                 if(!firstload)LoadStuff();
2436                                 else {
2437                                         Loadlevel(-1);
2438                                 }
2439
2440                                 mainmenu=0;
2441                                 gameon=1;
2442                                 OPENAL_SetPaused(channels[stream_music3], true);
2443                         }
2444                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
2445                                 float gLoc[3]={0,0,0};
2446                                 float vel[3]={0,0,0};
2447                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2448                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2449                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2450                                 OPENAL_SetVolume(channels[firestartsound], 256);
2451                                 OPENAL_SetPaused(channels[firestartsound], false);
2452                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2453
2454                                 flashr=1;
2455                                 flashg=0;
2456                                 flashb=0;
2457                                 flashamount=1;
2458                                 flashdelay=1;
2459
2460                                 startbonustotal=0;
2461
2462                                 loading=2;
2463                                 loadtime=0;
2464                                 targetlevel=7;
2465                                 if(firstload)TickOnceAfter();
2466                                 if(!firstload)LoadStuff();
2467                                 //else {
2468                                 for(i=0;i<255;i++){
2469                                         mapname[i]='\0';
2470                                 }
2471                                 mapname[0]=':';
2472                                 mapname[1]='D';
2473                                 mapname[2]='a';
2474                                 mapname[3]='t';
2475                                 mapname[4]='a';
2476                                 mapname[5]=':';
2477                                 mapname[6]='M';
2478                                 mapname[7]='a';
2479                                 mapname[8]='p';
2480                                 mapname[9]='s';
2481                                 mapname[10]=':';
2482                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2483                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2484                                 visibleloading=1;
2485                                 stillloading=1;
2486                                 Loadlevel(mapname);
2487                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2488                                 //}
2489                                 campaign=1;
2490                                 mainmenu=0;
2491                                 gameon=1;
2492                                 OPENAL_SetPaused(channels[stream_music3], true);
2493                         }
2494                         if(Button()&&!oldbutton&&selected==4){
2495                                 float gLoc[3]={0,0,0};
2496                                 float vel[3]={0,0,0};
2497                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2498                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2499                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2500                                 OPENAL_SetVolume(channels[fireendsound], 256);
2501                                 OPENAL_SetPaused(channels[fireendsound], false);
2502                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2503
2504                                 flashr=1;
2505                                 flashg=0;
2506                                 flashb=0;
2507                                 flashamount=1;
2508                                 flashdelay=1;
2509
2510                                 if(mainmenu==5&&gameon)mainmenu=2;
2511                                 if(mainmenu==5&&!gameon)mainmenu=1;
2512                         }
2513                         if(Button()&&!oldbutton&&selected==5){
2514                                 float gLoc[3]={0,0,0};
2515                                 float vel[3]={0,0,0};
2516                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2517                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2518                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2519                                 OPENAL_SetVolume(channels[fireendsound], 256);
2520                                 OPENAL_SetPaused(channels[fireendsound], false);
2521                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2522
2523                                 flashr=1;
2524                                 flashg=0;
2525                                 flashb=0;
2526                                 flashamount=1;
2527                                 flashdelay=1;
2528
2529                                 mainmenu=7;
2530                         }
2531                         if(Button()&&!oldbutton&&selected==3){
2532                                 float gLoc[3]={0,0,0};
2533                                 float vel[3]={0,0,0};
2534                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2535                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2536                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2537                                 OPENAL_SetVolume(channels[firestartsound], 256);
2538                                 OPENAL_SetPaused(channels[firestartsound], false);
2539                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2540
2541                                 flashr=1;
2542                                 flashg=0;
2543                                 flashb=0;
2544                                 flashamount=1;
2545                                 flashdelay=1;
2546
2547                                 mainmenu=6;
2548                         }
2549                         if(Button()&&!oldbutton&&selected==2){
2550                                 float gLoc[3]={0,0,0};
2551                                 float vel[3]={0,0,0};
2552                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2553                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2554                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2555                                 OPENAL_SetVolume(channels[firestartsound], 256);
2556                                 OPENAL_SetPaused(channels[firestartsound], false);
2557                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2558
2559                                 flashr=1;
2560                                 flashg=0;
2561                                 flashb=0;
2562                                 flashamount=1;
2563                                 flashdelay=1;
2564
2565                                 mainmenu=9;
2566                         }
2567                         if(Button())oldbutton=1;
2568                         else oldbutton=0;
2569                 }
2570                 if(mainmenu==9){
2571                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2572                                 float gLoc[3]={0,0,0};
2573                                 float vel[3]={0,0,0};
2574                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2575                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2576                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2577                                 OPENAL_SetVolume(channels[firestartsound], 256);
2578                                 OPENAL_SetPaused(channels[firestartsound], false);
2579                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2580
2581                                 flashr=1;
2582                                 flashg=0;
2583                                 flashb=0;
2584                                 flashamount=1;
2585                                 flashdelay=1;
2586
2587                                 startbonustotal=0;
2588
2589                                 loading=2;
2590                                 loadtime=0;
2591                                 targetlevel=selected;
2592                                 if(firstload)TickOnceAfter();
2593                                 if(!firstload)LoadStuff();
2594                                 else {
2595                                         Loadlevel(selected);
2596                                 }
2597                                 campaign=0;
2598
2599                                 mainmenu=0;
2600                                 gameon=1;
2601                                 OPENAL_SetPaused(channels[stream_music3], true);
2602                         }
2603                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2604                                 float gLoc[3]={0,0,0};
2605                                 float vel[3]={0,0,0};
2606                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2607                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2608                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2609                                 OPENAL_SetVolume(channels[fireendsound], 256);
2610                                 OPENAL_SetPaused(channels[fireendsound], false);
2611                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2612
2613                                 flashr=1;
2614                                 flashg=0;
2615                                 flashb=0;
2616                                 flashamount=1;
2617                                 flashdelay=1;
2618
2619                                 mainmenu=5;
2620                         }
2621                         if(Button())oldbutton=1;
2622                         else oldbutton=0;
2623                 }
2624                 if(mainmenu==11){
2625                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2626                                 float gLoc[3]={0,0,0};
2627                                 float vel[3]={0,0,0};
2628                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2629                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2630                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2631                                 OPENAL_SetVolume(channels[firestartsound], 256);
2632                                 OPENAL_SetPaused(channels[firestartsound], false);
2633                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2634
2635                                 flashr=1;
2636                                 flashg=0;
2637                                 flashb=0;
2638                                 flashamount=1;
2639                                 flashdelay=1;
2640
2641                                 startbonustotal=0;
2642
2643                                 loading=2;
2644                                 loadtime=0;
2645                                 targetlevel=selected;
2646                                 if(firstload)TickOnceAfter();
2647                                 if(!firstload)LoadStuff();
2648                                 else {
2649                                         Loadlevel(selected);
2650                                 }
2651                                 campaign=0;
2652
2653                                 mainmenu=0;
2654                                 gameon=1;
2655                                 OPENAL_SetPaused(channels[stream_music3], true);
2656                         }
2657                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2658                                 float gLoc[3]={0,0,0};
2659                                 float vel[3]={0,0,0};
2660                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2661                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2662                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2663                                 OPENAL_SetVolume(channels[fireendsound], 256);
2664                                 OPENAL_SetPaused(channels[fireendsound], false);
2665                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2666
2667                                 flashr=1;
2668                                 flashg=0;
2669                                 flashb=0;
2670                                 flashamount=1;
2671                                 flashdelay=1;
2672
2673                                 mainmenu=5;
2674                         }
2675                         if(Button())oldbutton=1;
2676                         else oldbutton=0;
2677                 }
2678                 if(mainmenu==10){
2679                         endgame=2;
2680                         if(Button()&&!oldbutton&&selected==3){
2681                                 float gLoc[3]={0,0,0};
2682                                 float vel[3]={0,0,0};
2683                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2684                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2685                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2686                                 OPENAL_SetVolume(channels[fireendsound], 256);
2687                                 OPENAL_SetPaused(channels[fireendsound], false);
2688                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2689
2690                                 flashr=1;
2691                                 flashg=0;
2692                                 flashb=0;
2693                                 flashamount=1;
2694                                 flashdelay=1;
2695
2696                                 mainmenu=5;
2697                         }
2698                         if(Button())oldbutton=1;
2699                         else oldbutton=0;
2700                 }
2701
2702                 if(mainmenu==6){
2703                         if(Button()&&!oldbutton&&selected!=-1){
2704                                 float gLoc[3]={0,0,0};
2705                                 float vel[3]={0,0,0};
2706                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2707                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2708                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2709                                 OPENAL_SetVolume(channels[firestartsound], 256);
2710                                 OPENAL_SetPaused(channels[firestartsound], false);
2711                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2712                         }
2713                         if(Button()&&!oldbutton&&selected==1){
2714                                 float gLoc[3]={0,0,0};
2715                                 float vel[3]={0,0,0};
2716                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2717                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2718                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2719                                 OPENAL_SetVolume(channels[fireendsound], 256);
2720                                 OPENAL_SetPaused(channels[fireendsound], false);
2721                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2722
2723                                 flashr=1;
2724                                 flashg=0;
2725                                 flashb=0;
2726                                 flashamount=1;
2727                                 flashdelay=1;
2728
2729                                 for(i=accountactive;i<numaccounts-1;i++){
2730                                         accountdifficulty[i]=accountdifficulty[i+1];
2731                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2732                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2733                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2734                                         }
2735                                         accountpoints[i]=accountpoints[i+1];
2736                                         for(j=0;j<50;j++){
2737                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2738                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2739                                         }
2740                                         for(j=0;j<60;j++){
2741                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2742                                         }
2743                                         for(j=0;j<256;j++){
2744                                                 accountname[i][j]=accountname[i+1][j];
2745                                         }
2746                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2747                                         accountprogress[i]=accountprogress[i+1];
2748                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2749                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2750                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2751                                 }
2752
2753                                 numaccounts--;
2754                                 accountactive=-1;
2755
2756
2757                                 mainmenu=7;
2758                         }
2759                         if(Button()&&!oldbutton&&selected==2){
2760                                 float gLoc[3]={0,0,0};
2761                                 float vel[3]={0,0,0};
2762                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2763                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2764                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2765                                 OPENAL_SetVolume(channels[fireendsound], 256);
2766                                 OPENAL_SetPaused(channels[fireendsound], false);
2767                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2768
2769                                 flashr=1;
2770                                 flashg=0;
2771                                 flashb=0;
2772                                 flashamount=1;
2773                                 flashdelay=1;
2774
2775                                 mainmenu=5;
2776                         }
2777                         if(Button())oldbutton=1;
2778                         else oldbutton=0;
2779                 }
2780                 if(mainmenu==7){
2781                         if(Button()&&!oldbutton&&selected!=-1){
2782                                 float gLoc[3]={0,0,0};
2783                                 float vel[3]={0,0,0};
2784                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2785                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2786                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2787                                 OPENAL_SetVolume(channels[firestartsound], 256);
2788                                 OPENAL_SetPaused(channels[firestartsound], false);
2789                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2790                         }
2791                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2792                                 entername=1;
2793                         }
2794                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2795                                 accountactive=selected-1;
2796                                 mainmenu=5;
2797                                 flashr=1;
2798                                 flashg=0;
2799                                 flashb=0;
2800                                 flashamount=1;
2801                                 flashdelay=1;
2802                         }
2803                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2804                                 float gLoc[3]={0,0,0};
2805                                 float vel[3]={0,0,0};
2806                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2807                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2808                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2809                                 OPENAL_SetVolume(channels[fireendsound], 256);
2810                                 OPENAL_SetPaused(channels[fireendsound], false);
2811                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2812
2813                                 flashr=1;
2814                                 flashg=0;
2815                                 flashb=0;
2816                                 flashamount=1;
2817                                 flashdelay=1;
2818
2819                                 mainmenu=1;
2820
2821                                 for(j=0;j<255;j++){
2822                                         displaytext[0][j]=' ';
2823                                 }
2824                                 displaychars[0]=0;
2825                                 displayselected=0;
2826                                 entername=0;
2827                         }
2828                         if(Button())oldbutton=1;
2829                         else oldbutton=0;
2830                 }
2831                 if(mainmenu==8){
2832                         if(Button()&&!oldbutton&&selected!=-1){
2833                                 float gLoc[3]={0,0,0};
2834                                 float vel[3]={0,0,0};
2835                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2836                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2837                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2838                                 OPENAL_SetVolume(channels[firestartsound], 256);
2839                                 OPENAL_SetPaused(channels[firestartsound], false);
2840                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2841
2842                                 if(selected==0)accountdifficulty[accountactive]=0;
2843                                 if(selected==1)accountdifficulty[accountactive]=1;
2844                                 if(selected==2)accountdifficulty[accountactive]=2;
2845
2846                                 mainmenu=5;
2847
2848                                 flashr=1;
2849                                 flashg=0;
2850                                 flashb=0;
2851                                 flashamount=1;
2852                                 flashdelay=1;
2853
2854                         }
2855                         if(Button())oldbutton=1;
2856                         else oldbutton=0;
2857                 }
2858
2859
2860                 if(Button())oldbutton=1;
2861                 else oldbutton=0;
2862
2863                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
2864                         tryquit=1;
2865                         if(mainmenu==3){
2866                                 if(newdetail>2)newdetail=detail;
2867                                 if(newdetail<0)newdetail=detail;
2868                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2869                                 if(newscreenheight<0)newscreenheight=screenheight;
2870
2871                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2872                                 opstream << "Screenwidth:\n";
2873                                 opstream << newscreenwidth;
2874                                 opstream << "\nScreenheight:\n";
2875                                 opstream << newscreenheight;
2876                                 opstream << "\nMouse sensitivity:\n";
2877                                 opstream << usermousesensitivity;
2878                                 opstream << "\nBlur(0,1):\n";
2879                                 opstream << ismotionblur;
2880                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2881                                 opstream << newdetail;
2882                                 opstream << "\nFloating jump:\n";
2883                                 opstream << floatjump;
2884                                 opstream << "\nMouse jump:\n";
2885                                 opstream << mousejump;
2886                                 opstream << "\nAmbient sound:\n";
2887                                 opstream << ambientsound;
2888                                 opstream << "\nBlood (0,1,2):\n";
2889                                 opstream << bloodtoggle;
2890                                 opstream << "\nAuto slomo:\n";
2891                                 opstream << autoslomo;
2892                                 opstream << "\nFoliage:\n";
2893                                 opstream << foliage;
2894                                 opstream << "\nMusic:\n";
2895                                 opstream << musictoggle;
2896                                 opstream << "\nTrilinear:\n";
2897                                 opstream << trilinear;
2898                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2899                                 opstream << decals;
2900                                 opstream << "\nInvert mouse:\n";
2901                                 opstream << invertmouse;
2902                                 opstream << "\nGamespeed:\n";
2903                                 if(oldgamespeed==0)oldgamespeed=1;
2904                                 opstream << oldgamespeed;
2905                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2906                                 opstream << difficulty;
2907                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2908                                 opstream << damageeffects;
2909                                 opstream << "\nText:\n";
2910                                 opstream << texttoggle;
2911                                 opstream << "\nDebug:\n";
2912                                 opstream << debugmode;
2913                                 opstream << "\nVBL Sync:\n";
2914                                 opstream << vblsync;
2915                                 opstream << "\nShow Points:\n";
2916                                 opstream << showpoints;
2917                                 opstream << "\nAlways Blur:\n";
2918                                 opstream << alwaysblur;
2919                                 opstream << "\nImmediate mode (turn on on G5):\n";
2920                                 opstream << immediate;
2921                                 opstream << "\nVelocity blur:\n";
2922                                 opstream << velocityblur;
2923                             opstream << "\nVolume:\n";
2924                         opstream << volume;
2925                                 opstream << "\nForward key:\n";
2926                                 opstream << KeyToChar(forwardkey);
2927                                 opstream << "\nBack key:\n";
2928                                 opstream << KeyToChar(backkey);
2929                                 opstream << "\nLeft key:\n";
2930                                 opstream << KeyToChar(leftkey);
2931                                 opstream << "\nRight key:\n";
2932                                 opstream << KeyToChar(rightkey);
2933                                 opstream << "\nJump key:\n";
2934                                 opstream << KeyToChar(jumpkey);
2935                                 opstream << "\nCrouch key:\n";
2936                                 opstream << KeyToChar(crouchkey);
2937                                 opstream << "\nDraw key:\n";
2938                                 opstream << KeyToChar(drawkey);
2939                                 opstream << "\nThrow key:\n";
2940                                 opstream << KeyToChar(throwkey);
2941                                 opstream << "\nAttack key:\n";
2942                                 opstream << KeyToChar(attackkey);
2943                                 opstream << "\nChat key:\n";
2944                                 opstream << KeyToChar(chatkey);
2945                                 opstream.close();
2946                         }
2947                 }
2948
2949                 if(mainmenu==1||mainmenu==2){
2950                         if(loaddistrib>4)transition+=multiplier/8;
2951                         if(transition>1){
2952                                 transition=0;
2953                                 anim++;
2954                                 if(anim>4)anim=0;
2955                                 loaddistrib=0;
2956                         }
2957                 }
2958                 OPENAL_SetFrequency(channels[stream_music3], 22050);
2959
2960                 if(entername){
2961                         for(i=0;i<140;i++){
2962                                 if(IsKeyDown(theKeyMap, i)){
2963                                         togglekeydelay[i]+=multiplier;
2964                                         if(togglekeydelay[i]>.4){
2965                                                 togglekey[i]=0;
2966                                                 togglekeydelay[i]=.36;
2967                                         }
2968                                         if(!togglekey[i]){
2969                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
2970                                                         for(j=255;j>=displayselected+1;j--){
2971                                                                 displaytext[0][j]=displaytext[0][j-1];
2972                                                         }
2973                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
2974                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
2975                                                         displayselected++;
2976                                                         displaychars[0]++;
2977                                                 }
2978                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
2979                                                         for(j=displayselected-1;j<255;j++){
2980                                                                 displaytext[0][j]=displaytext[0][j+1];
2981                                                         }
2982                                                         displaytext[0][255]=' ';
2983                                                         displayselected--;
2984                                                         displaychars[0]--;
2985                                                 }
2986                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
2987                                                         displayselected--;
2988                                                 }
2989                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
2990                                                         displayselected++;
2991                                                 }
2992                                                 if(i==MAC_RETURN_KEY&&entername){
2993                                                         if(displaychars[0]){
2994                                                                 numaccounts++;
2995                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
2996                                                                 accountactive=numaccounts-1;
2997                                                                 accountdifficulty[accountactive]=1;
2998                                                                 accountprogress[accountactive]=0;
2999                                                                 accountpoints[accountactive]=0;
3000                                                                 accountcampaigntime[accountactive]=0;
3001                                                                 accountcampaignscore[accountactive]=0;
3002                                                                 accountcampaignfasttime[accountactive]=0;
3003                                                                 accountcampaignhighscore[accountactive]=0;
3004                                                                 for(j=0;j<50;j++){
3005                                                                         accounthighscore[accountactive][j]=0;
3006                                                                         accountfasttime[accountactive][j]=0;
3007                                                                 }
3008                                                                 for(j=0;j<60;j++){
3009                                                                         accountunlocked[accountactive][j]=0;
3010                                                                 }
3011                                                                 accountcampaignchoicesmade[accountactive]=0;
3012
3013                                                                 for(j=0;j<255;j++){
3014                                                                         displaytext[0][j]=' ';
3015                                                                 }
3016                                                                 displaychars[0]=0;
3017                                                                 displayselected=0;
3018                                                                 entername=0;
3019
3020                                                                 mainmenu=8;
3021
3022                                                                 flashr=1;
3023                                                                 flashg=0;
3024                                                                 flashb=0;
3025                                                                 flashamount=1;
3026                                                                 flashdelay=1;
3027
3028                                                                 float gLoc[3]={0,0,0};
3029                                                                 float vel[3]={0,0,0};
3030                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3031                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3032                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3033                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3034                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3035                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3036
3037                                                                 for(j=0;j<255;j++){
3038                                                                         displaytext[0][j]=' ';
3039                                                                 }
3040                                                                 displaychars[0]=0;
3041
3042
3043                                                                 displayselected=0;
3044                                                         }}
3045
3046                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3047                                                         if(displaychars[0]){
3048                                                                 sprintf (registrationname, "%s", displaytext[0]);
3049                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3050
3051                                                                 mainmenu=5;
3052                         
3053                                                                 flashr=1;
3054                                                                 flashg=0;
3055                                                                 flashb=0;
3056                                                                 flashamount=1;
3057                                                                 flashdelay=1;
3058
3059                                                                 float gLoc[3]={0,0,0};
3060                                                                 float vel[3]={0,0,0};
3061                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3062                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3063                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3064                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3065                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3066                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3067
3068                                                                 for(j=0;j<255;j++){
3069                                                                         displaytext[0][j]=' ';
3070                                                                 }
3071                                                                 displaychars[0]=0;
3072                         
3073                                                                 displayselected=0;
3074                                                         }}
3075                                         }
3076                                         togglekey[i]=1;
3077                                 }
3078                                 else {
3079                                         togglekey[i]=0;
3080                                         togglekeydelay[i]=0;
3081                                 }
3082                         }
3083
3084                         displayblinkdelay-=multiplier;
3085                         if(displayblinkdelay<=0){
3086                                 displayblinkdelay=.3;
3087                                 displayblink=1-displayblink;
3088                         }
3089                 }
3090         }
3091
3092         if(!mainmenu){
3093                 if(hostile==1)hostiletime+=multiplier;
3094                 else hostiletime=0;
3095                 if(!winfreeze)leveltime+=multiplier;
3096                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3097                         chatting=0;
3098                         console=0;
3099                         freeze=0;
3100                         displaychars[0]=0;
3101                 }
3102
3103                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3104                         chatting=1;
3105                         chattogglekeydown=1;
3106                         togglekey[chatkey]=1;
3107                         togglekeydelay[chatkey]=-20;
3108                 }
3109
3110                 if(!IsKeyDown(theKeyMap, chatkey)){
3111                         chattogglekeydown=0;
3112                 }
3113
3114                 if(chatting){
3115                         for(i=0;i<140;i++){
3116                                 if(IsKeyDown(theKeyMap, i)){
3117                                         togglekeydelay[i]+=multiplier;
3118                                         if(togglekeydelay[i]>.4){
3119                                                 togglekey[i]=0;
3120                                                 togglekeydelay[i]=.36;
3121                                         }
3122                                         if(!togglekey[i]){
3123                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3124                                                         for(j=255;j>=displayselected+1;j--){
3125                                                                 displaytext[0][j]=displaytext[0][j-1];
3126                                                         }
3127                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3128                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3129                                                         displayselected++;
3130                                                         displaychars[0]++;
3131                                                 }
3132                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3133                                                         for(j=displayselected-1;j<255;j++){
3134                                                                 displaytext[0][j]=displaytext[0][j+1];
3135                                                         }
3136                                                         displaytext[0][255]=' ';
3137                                                         displayselected--;
3138                                                         displaychars[0]--;
3139                                                 }
3140                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3141                                                         displayselected--;
3142                                                 }
3143                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3144                                                         displayselected++;
3145                                                 }
3146                                                 if(i==MAC_RETURN_KEY){
3147                                                         if(displaychars[0]){
3148                                                                 /*for(j=0;j<displaychars[0];j++){
3149                                                                 talkname[j]=displaytext[0][j];
3150                                                                 }
3151                                                                 talkname[displaychars[0]]='\0';
3152                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3153                                                                 //NetworkSendInformation(chatname);
3154                                                                 */
3155                                                                 for(j=0;j<255;j++){
3156                                                                         displaytext[0][j]=' ';
3157                                                                 }
3158                                                                 displaychars[0]=0;
3159                                                                 displayselected=0;
3160                                                                 chatting=0;
3161                                                         }
3162                                                 }
3163                                         }
3164                                         togglekey[i]=1;
3165                                 }
3166                                 else {
3167                                         togglekey[i]=0;
3168                                         togglekeydelay[i]=0;
3169                                 }
3170                         }
3171
3172                         displayblinkdelay-=multiplier;
3173                         if(displayblinkdelay<=0){
3174                                 displayblinkdelay=.3;
3175                                 displayblink=1-displayblink;
3176                         }
3177                 }
3178
3179                 if(chatting)keyboardfrozen=1;
3180
3181                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3182                         freeze=1-freeze;
3183                         if(freeze){
3184                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3185                         }
3186                         freezetogglekeydown=1;
3187                 }
3188
3189                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3190                         freezetogglekeydown=0;
3191                 }
3192
3193                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3194                         console=1-console;
3195                         if(!console)freeze=0;
3196                         if(console){
3197                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3198                         }
3199                         consoletogglekeydown=1;
3200                 }
3201
3202                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3203                         consoletogglekeydown=0;
3204                 }
3205
3206                 if(console)freeze=1;
3207
3208                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3209                         for(i=0;i<140;i++){
3210                                 if(IsKeyDown(theKeyMap, i)){
3211                                         togglekeydelay[i]+=multiplier;
3212                                         if(togglekeydelay[i]>.4){
3213                                                 togglekey[i]=0;
3214                                                 togglekeydelay[i]=.36;
3215                                         }
3216                                         if(!togglekey[i]){
3217                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3218                                                         for(j=255;j>=consoleselected+1;j--){
3219                                                                 consoletext[0][j]=consoletext[0][j-1];
3220                                                         }
3221                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3222                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3223                                                         consoleselected++;
3224                                                         consolechars[0]++;
3225                                                 }
3226                                                 else if(i==MAC_ENTER_KEY){
3227                                                         for(j=255;j>=consoleselected+1;j--){
3228                                                                 consoletext[0][j]=consoletext[0][j-1];
3229                                                         }
3230                                                         consoletext[0][consoleselected]='\n';
3231                                                         consoleselected++;
3232                                                         consolechars[0]++;
3233                                                 }
3234                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3235                                                         for(j=consoleselected-1;j<255;j++){
3236                                                                 consoletext[0][j]=consoletext[0][j+1];
3237                                                         }
3238                                                         consoletext[0][255]=' ';
3239                                                         consoleselected--;
3240                                                         consolechars[0]--;
3241                                                 }
3242                                                 if(i==MAC_ARROW_UP_KEY){
3243                                                         if(archiveselected<14)archiveselected++;
3244                                                         for(j=0;j<255;j++){
3245                                                                 consolechars[0]=consolechars[archiveselected];
3246                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3247                                                                 consoleselected=consolechars[0];
3248                                                         }
3249                                                 }
3250                                                 if(i==MAC_ARROW_DOWN_KEY){
3251                                                         if(archiveselected>0)archiveselected--;
3252                                                         for(j=0;j<255;j++){
3253                                                                 consolechars[0]=consolechars[archiveselected];
3254                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3255                                                                 consoleselected=consolechars[0];
3256                                                         }
3257                                                 }
3258                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3259                                                         consoleselected--;
3260                                                 }
3261                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3262                                                         consoleselected++;
3263                                                 }
3264                                                 if(i==MAC_RETURN_KEY){
3265                                                         archiveselected=0;
3266                                                         donesomething=0;
3267                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3268                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3269                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3270                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3271                                                                 donesomething=1;
3272                                                                 tryquit=1;
3273                                                         }
3274                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3275                                                         for(j=5;j<consolechars[0];j++){
3276                                                         talkname[j-5]=consoletext[0][j];
3277                                                         }
3278                                                         talkname[consolechars[0]-5]='\0';
3279                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3280                                                         //NetworkSendInformation(chatname);
3281                                                         donesomething=1;
3282                                                         }
3283                                                         if(Compare(consoletext[0],"name ",0,4)){
3284                                                         int numchars;
3285                                                         numchars=consolechars[0]-5;
3286                                                         if(numchars>32)numchars=32;
3287                                                         for(j=5;j<numchars+5;j++){
3288                                                         talkname[j-5]=consoletext[0][j];
3289                                                         }
3290                                                         talkname[numchars]='\0';
3291                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3292                                                         //NetworkSendInformation(chatname);
3293                                                         sprintf (playerName, "%s",talkname);
3294                                                         //NetworkSendName(playerName);
3295                                                         donesomething=1;
3296                                                         }*/
3297                                                         if(Compare(consoletext[0],"map ",0,3)){
3298                                                                 mapname[0]=':';
3299                                                                 mapname[1]='D';
3300                                                                 mapname[2]='a';
3301                                                                 mapname[3]='t';
3302                                                                 mapname[4]='a';
3303                                                                 mapname[5]=':';
3304                                                                 mapname[6]='M';
3305                                                                 mapname[7]='a';
3306                                                                 mapname[8]='p';
3307                                                                 mapname[9]='s';
3308                                                                 mapname[10]=':';
3309                                                                 for(j=4;j<consolechars[0];j++){
3310                                                                         mapname[j-4+11]=consoletext[0][j];
3311                                                                 }
3312                                                                 mapname[consolechars[0]-4+11]='\0';
3313                                                                 Loadlevel(mapname);
3314                                                                 whichlevel=-2;
3315                                                                 campaign=0;
3316                                                                 donesomething=1;
3317                                                         }
3318                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3319                                                         int v;
3320                                                         unsigned char playerNameStr[32];
3321                                                         char theIPAddress[256];
3322                                                         char thePort[32];
3323                                                         NMUInt32 port = 25710;
3324
3325                                                         strcpy(playerName, "Client");
3326                                                         GameC2PStr( playerName, playerNameStr );
3327
3328                                                         for(j=0;j<consolechars[0]-8;j++){
3329                                                         theIPAddress[j]=consoletext[0][j+8];
3330                                                         }
3331                                                         theIPAddress[consolechars[0]-8]='\0';
3332
3333                                                         sprintf( thePort, "%li", port );
3334                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3335                                                         if(v)
3336                                                         {
3337                                                         if(consolechars[0]>0){
3338                                                         for(k=14;k>=1;k--){
3339                                                         for(j=0;j<255;j++){
3340                                                         consoletext[k][j]=consoletext[k-1][j];
3341                                                         }
3342                                                         consolechars[k]=consolechars[k-1];
3343                                                         }
3344                                                         for(j=0;j<255;j++){
3345                                                         consoletext[0][j]=' ';
3346                                                         }
3347                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3348                                                         else sprintf (consoletext[0], "Could not open connection");
3349
3350                                                         consolechars[0]=255;
3351                                                         consoleselected=0;
3352                                                         }
3353                                                         }
3354                                                         else
3355                                                         {
3356                                                         donesomething=1;
3357                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3358                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3359                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3360
3361                                                         if(consolechars[0]>0){
3362                                                         for(k=14;k>=1;k--){
3363                                                         for(j=0;j<255;j++){
3364                                                         consoletext[k][j]=consoletext[k-1][j];
3365                                                         }
3366                                                         consolechars[k]=consolechars[k-1];
3367                                                         }
3368                                                         for(j=0;j<255;j++){
3369                                                         consoletext[0][j]=' ';
3370                                                         }
3371                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3372
3373                                                         consolechars[0]=255;
3374                                                         consoleselected=0;
3375                                                         }
3376                                                         }
3377                                                         }
3378
3379                                                         if(Compare(consoletext[0],"host ",0,4)){
3380                                                         unsigned char gameNameStr[32], playerNameStr[32];
3381                                                         char gameName[32];//, playerName[32];
3382                                                         NMUInt32 port;
3383                                                         int players;
3384                                                         int v;
3385
3386                                                         port = 25710;
3387                                                         players =4;
3388
3389                                                         strcpy(gameName, "Host's game");
3390                                                         strcpy(playerName, "Host");
3391                                                         GameC2PStr( gameName, gameNameStr );
3392                                                         GameC2PStr( playerName, playerNameStr );
3393
3394                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3395                                                         if(v)
3396                                                         {
3397                                                         if(consolechars[0]>0){
3398                                                         for(k=14;k>=1;k--){
3399                                                         for(j=0;j<255;j++){
3400                                                         consoletext[k][j]=consoletext[k-1][j];
3401                                                         }
3402                                                         consolechars[k]=consolechars[k-1];
3403                                                         }
3404                                                         for(j=0;j<255;j++){
3405                                                         consoletext[0][j]=' ';
3406                                                         }
3407                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3408
3409                                                         consolechars[0]=255;
3410                                                         consoleselected=0;
3411                                                         }
3412                                                         }
3413                                                         else
3414                                                         {
3415                                                         donesomething=1;
3416                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3417                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3418                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3419
3420                                                         if(consolechars[0]>0){
3421                                                         for(k=14;k>=1;k--){
3422                                                         for(j=0;j<255;j++){
3423                                                         consoletext[k][j]=consoletext[k-1][j];
3424                                                         }
3425                                                         consolechars[k]=consolechars[k-1];
3426                                                         }
3427                                                         for(j=0;j<255;j++){
3428                                                         consoletext[0][j]=' ';
3429                                                         }
3430                                                         sprintf (consoletext[0], "Game hosted");
3431
3432                                                         consolechars[0]=255;
3433                                                         consoleselected=0;
3434                                                         }
3435                                                         }
3436                                                         }
3437                                                         */
3438                                                         if(Compare(consoletext[0],"save ",0,4)){
3439                                                                 mapname[0]=':';
3440                                                                 mapname[1]='D';
3441                                                                 mapname[2]='a';
3442                                                                 mapname[3]='t';
3443                                                                 mapname[4]='a';
3444                                                                 mapname[5]=':';
3445                                                                 mapname[6]='M';
3446                                                                 mapname[7]='a';
3447                                                                 mapname[8]='p';
3448                                                                 mapname[9]='s';
3449                                                                 mapname[10]=':';
3450                                                                 for(j=5;j<consolechars[0];j++){
3451                                                                         mapname[j-5+11]=consoletext[0][j];
3452                                                                 }
3453                                                                 mapname[consolechars[0]-5+11]='\0';
3454
3455                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3456                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3457                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3458
3459                                                                 int mapvers;
3460                                                                 mapvers=12;
3461
3462
3463                                                                 FILE                    *tfile;
3464                                                                 tfile=fopen( mapname, "wb" );
3465                                                                 fpackf(tfile, "Bi", mapvers);
3466                                                                 //fpackf(tfile, "Bi", indemo);
3467                                                                 fpackf(tfile, "Bi", maptype);
3468                                                                 fpackf(tfile, "Bi", hostile);
3469                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3470                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3471                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3472                                                                 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);
3473                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3474                                                                         for(j=0;j<player[0].num_weapons;j++){
3475                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3476                                                                         }
3477
3478                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3479                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3480                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3481                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3482
3483                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3484
3485                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3486
3487                                                                         fpackf(tfile, "Bi", numdialogues);
3488                                                                         if(numdialogues)
3489                                                                                 for(k=0;k<numdialogues;k++){
3490                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3491                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3492                                                                                         for(l=0;l<10;l++){
3493                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3494                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3495                                                                                         }
3496                                                                                         if(numdialogueboxes)
3497                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3498                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3499                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3500                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3501                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3502                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3503
3504                                                                                                         templength=strlen(dialoguetext[k][l]);
3505                                                                                                         fpackf(tfile, "Bi",(templength));
3506                                                                                                         for(m=0;m<templength;m++){
3507                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3508                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3509                                                                                                         }
3510
3511                                                                                                         templength=strlen(dialoguename[k][l]);
3512                                                                                                         fpackf(tfile, "Bi",templength);
3513                                                                                                         for(m=0;m<templength;m++){
3514                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3515                                                                                                                 if(dialoguename[k][l][m]=='\0')break;
3516                                                                                                         }
3517
3518                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3519                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3520                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3521
3522                                                                                                         for(m=0;m<10;m++)
3523                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3524
3525                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3526                                                                                                 }
3527                                                                                 }
3528
3529                                                                                 if(player[0].numclothes)
3530                                                                                         for(k=0;k<player[0].numclothes;k++){
3531                                                                                                 templength=strlen(player[0].clothes[k]);
3532                                                                                                 fpackf(tfile, "Bi", templength);
3533                                                                                                 for(l=0;l<templength;l++)
3534                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3535                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
3536                                                                                         }
3537
3538                                                                                         fpackf(tfile, "Bi", environment);
3539
3540                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3541
3542                                                                                         if(objects.numobjects)
3543                                                                                                 for(k=0;k<objects.numobjects;k++){
3544                                                                                                         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]);
3545                                                                                                 }
3546
3547                                                                                                 fpackf(tfile, "Bi", numhotspots);
3548                                                                                                 if(numhotspots)
3549                                                                                                         for(i=0;i<numhotspots;i++){
3550                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3551                                                                                                                 templength=strlen(hotspottext[i]);
3552                                                                                                                 fpackf(tfile, "Bi",templength);
3553                                                                                                                 for(l=0;l<templength;l++)
3554                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3555                                                                                                         }
3556
3557                                                                                                         fpackf(tfile, "Bi", numplayers);
3558                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3559                                                                                                                 for(j=1;j<numplayers;j++){
3560                                                                                                                         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);
3561                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3562                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3563                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3564                                                                                                                                 }
3565                                                                                                                                 if(player[j].numwaypoints<30){
3566                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3567                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3568                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3569                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3570                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3571                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3572                                                                                                                                         }
3573                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3574                                                                                                                                 }
3575                                                                                                                                 else{
3576                                                                                                                                         player[j].numwaypoints=0;
3577                                                                                                                                         player[j].waypoint=0;
3578                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3579                                                                                                                                 }
3580
3581                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3582                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3583                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3584                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3585
3586                                                                                                                                 if(player[j].creature==wolftype){
3587                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3588                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3589                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3590                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3591                                                                                                                                 }
3592
3593                                                                                                                                 if(player[j].creature==rabbittype){
3594                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3595                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3596                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3597                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3598                                                                                                                                 }
3599
3600                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3601
3602
3603
3604                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3605                                                                                                                                 if(player[j].numclothes)
3606                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3607                                                                                                                                                 int templength;
3608                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3609                                                                                                                                                 fpackf(tfile, "Bi", templength);
3610                                                                                                                                                 for(l=0;l<templength;l++)
3611                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3612                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
3613                                                                                                                                         }
3614                                                                                                                 }
3615
3616                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3617                                                                                                                 if(numpathpoints)
3618                                                                                                                         for(j=0;j<numpathpoints;j++){
3619                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3620                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3621                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3622                                                                                                                                 }
3623                                                                                                                         }
3624
3625                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3626
3627
3628                                                                                                                         fclose(tfile);
3629                                                                                                                         donesomething=1;
3630
3631                                                                                                                         /*
3632                                                                                                                         FILE                    *tfile;
3633                                                                                                                         tfile=fopen( mapname, "wb" );
3634                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3635                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3636                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3637                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3638                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3639                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3640                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3641                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3642                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3643                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3644                                                                                                                         }
3645
3646                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3647                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3648                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3649                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3650                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3651                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3652                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3653                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3654                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3655                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3656                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3657
3658                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3659                                                                                                                         if(player[0].numclothes)
3660                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3661                                                                                                                         int templength;
3662                                                                                                                         templength=strlen(player[0].clothes[k]);
3663                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3664                                                                                                                         for(l=0;l<templength;l++)
3665                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3666                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);
3667                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);
3668                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);
3669                                                                                                                         }
3670
3671                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3672
3673                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3674
3675                                                                                                                         for(k=0;k<objects.numobjects;k++){
3676                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3677                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3678                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3679                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3680                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3681                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3682                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3683                                                                                                                         }
3684
3685                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3686                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3687                                                                                                                         for(j=1;j<numplayers;j++){
3688                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3689                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3690                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3691                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3692                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3693                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3694                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3695                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3696                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3697                                                                                                                         }
3698                                                                                                                         if(player[j].numwaypoints<30){
3699                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3700                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3701                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3702                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3703                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3704                                                                                                                         }
3705                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3706                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3707                                                                                                                         }
3708                                                                                                                         else{
3709                                                                                                                         player[j].numwaypoints=0;
3710                                                                                                                         player[j].waypoint=0;
3711                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3712                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3713                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3714                                                                                                                         }
3715                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
3716                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
3717                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
3718                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
3719                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
3720                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
3721                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
3722                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
3723                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
3724                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
3725                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
3726
3727                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
3728                                                                                                                         if(player[j].numclothes)
3729                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3730                                                                                                                         int templength;
3731                                                                                                                         templength=strlen(player[j].clothes[k]);
3732                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3733                                                                                                                         for(l=0;l<templength;l++)
3734                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
3735                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);
3736                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);
3737                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);
3738                                                                                                                         }
3739                                                                                                                         }
3740                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3741                                                                                                                         if(numpathpoints)
3742                                                                                                                         for(j=0;j<numpathpoints;j++){
3743                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
3744                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
3745                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
3746                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3747                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
3748                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3749                                                                                                                         }
3750                                                                                                                         }
3751
3752                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
3753                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
3754                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
3755
3756                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
3757
3758                                                                                                                         fclose(tfile);
3759                                                                                                                         donesomething=1;*/
3760                                                         }
3761                                                         /*
3762                                                         if(Compare(consoletext[0],"save ",0,4)){
3763                                                         mapname[0]=':';
3764                                                         mapname[1]='D';
3765                                                         mapname[2]='a';
3766                                                         mapname[3]='t';
3767                                                         mapname[4]='a';
3768                                                         mapname[5]=':';
3769                                                         mapname[6]='M';
3770                                                         mapname[7]='a';
3771                                                         mapname[8]='p';
3772                                                         mapname[9]='s';
3773                                                         mapname[10]=':';
3774                                                         for(j=5;j<consolechars[0];j++){
3775                                                         mapname[j-5+11]=consoletext[0][j];
3776                                                         }
3777                                                         mapname[consolechars[0]-5+11]='\0';
3778
3779                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3780                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3781                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3782
3783                                                         FILE                    *tfile;
3784                                                         tfile=fopen( mapname, "wb" );
3785                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
3786                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3787                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3788                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3789                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3790                                                         for(j=0;j<player[0].num_weapons;j++){
3791                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3792                                                         }
3793                                                         fwrite( &environment, 1, sizeof(int), tfile );
3794
3795                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3796                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
3797                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
3798                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
3799                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
3800
3801                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3802                                                         if(numplayers>1&&numplayers<maxplayers)
3803                                                         for(j=1;j<numplayers;j++){
3804                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
3805                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3806                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3807                                                         for(k=0;k<player[j].num_weapons;k++){
3808                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3809                                                         }
3810                                                         if(player[j].numwaypoints<30){
3811                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3812                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
3813                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3814                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3815                                                         }
3816                                                         else{
3817                                                         player[j].numwaypoints=0;
3818                                                         player[j].waypoint=0;
3819                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3820                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3821                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3822                                                         }
3823                                                         }
3824                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3825                                                         if(numpathpoints)
3826                                                         for(j=0;j<numpathpoints;j++){
3827                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
3828                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3829                                                         for(k=0;k<numpathpointconnect[j];k++){
3830                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3831                                                         }
3832                                                         }
3833                                                         fclose(tfile);
3834                                                         donesomething=1;
3835                                                         }*/
3836                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
3837                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
3838                                                                 donesomething=1;
3839                                                         }
3840                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
3841                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
3842                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
3843                                                         donesomething=1;
3844                                                         }*/
3845
3846                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
3847                                                                 for(j=6;j<consolechars[0];j++){
3848                                                                         mapname[j-6]=consoletext[0][j];
3849                                                                 }
3850
3851                                                                 tintr=atof(mapname);
3852
3853                                                                 donesomething=1;
3854                                                         }
3855
3856                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
3857                                                                 for(j=6;j<consolechars[0];j++){
3858                                                                         mapname[j-6]=consoletext[0][j];
3859                                                                 }
3860
3861                                                                 player[0].speedmult=atof(mapname);
3862
3863                                                                 donesomething=1;
3864                                                         }
3865
3866                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
3867                                                                 for(j=9;j<consolechars[0];j++){
3868                                                                         mapname[j-9]=consoletext[0][j];
3869                                                                 }
3870
3871                                                                 player[0].power=atof(mapname);
3872
3873                                                                 donesomething=1;
3874                                                         }
3875
3876                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
3877                                                                 for(j=13;j<consolechars[0];j++){
3878                                                                         mapname[j-13]=consoletext[0][j];
3879                                                                 }
3880
3881                                                                 viewdistance=atof(mapname)*100;
3882
3883                                                                 donesomething=1;
3884                                                         }
3885
3886                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
3887                                                                 for(j=10;j<consolechars[0];j++){
3888                                                                         mapname[j-10]=consoletext[0][j];
3889                                                                 }
3890
3891                                                                 fadestart=atof(mapname);
3892
3893                                                                 donesomething=1;
3894                                                         }
3895
3896                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
3897                                                                 for(j=6;j<consolechars[0];j++){
3898                                                                         mapname[j-6]=consoletext[0][j];
3899                                                                 }
3900
3901                                                                 player[0].power=atof(mapname);
3902
3903                                                                 donesomething=1;
3904                                                         }
3905
3906                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
3907                                                                 for(j=6;j<consolechars[0];j++){
3908                                                                         mapname[j-6]=consoletext[0][j];
3909                                                                 }
3910
3911                                                                 slomospeed=atof(mapname);
3912                                                                 slomo=1-slomo;
3913                                                                 slomodelay=1000;
3914
3915                                                                 donesomething=1;
3916                                                         }
3917
3918                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
3919                                                                 for(j=8;j<consolechars[0];j++){
3920                                                                         mapname[j-8]=consoletext[0][j];
3921                                                                 }
3922
3923                                                                 slomofreq=atoi(mapname);
3924
3925                                                                 donesomething=1;
3926                                                         }
3927
3928                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
3929                                                                 for(j=5;j<consolechars[0];j++){
3930                                                                         mapname[j-5]=consoletext[0][j];
3931                                                                 }
3932
3933                                                                 player[0].scale=atof(mapname)*.2;
3934
3935                                                                 donesomething=1;
3936                                                         }
3937
3938                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
3939                                                                 int closest=-1;
3940                                                                 float closestdist=-1;
3941                                                                 float distance;
3942                                                                 if(numplayers>1)
3943                                                                         for(i=1;i<numplayers;i++){
3944                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
3945                                                                                 if(closestdist==-1||distance<closestdist){
3946                                                                                         closestdist=distance;
3947                                                                                         closest=i;
3948                                                                                 }
3949                                                                         }
3950
3951                                                                         for(j=9;j<consolechars[0];j++){
3952                                                                                 mapname[j-9]=consoletext[0][j];
3953                                                                         }
3954
3955                                                                         player[closest].scale=atof(mapname)*.2;
3956
3957                                                                         donesomething=1;
3958                                                         }
3959
3960                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
3961                                                                 int startpoint;
3962                                                                 int alldone;
3963
3964                                                                 int closest=-1;
3965                                                                 float closestdist=-1;
3966                                                                 float distance;
3967                                                                 if(numplayers>1)
3968                                                                         for(i=1;i<numplayers;i++){
3969                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
3970                                                                                 if(closestdist==-1||distance<closestdist){
3971                                                                                         closestdist=distance;
3972                                                                                         closest=i;
3973                                                                                 }
3974                                                                         }
3975
3976                                                                         alldone=0;
3977                                                                         startpoint=15;
3978                                                                         j=startpoint;
3979                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3980                                                                                 mapname[j-startpoint]=consoletext[0][j];
3981                                                                                 j++;
3982                                                                                 if(consoletext[0][j]=='\0')alldone=1;
3983                                                                         }
3984                                                                         mapname[j-startpoint]='\0';
3985
3986                                                                         headprop=atof(mapname);
3987
3988                                                                         j++;
3989                                                                         startpoint=j;
3990                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3991                                                                                 mapname[j-startpoint]=consoletext[0][j];
3992                                                                                 j++;
3993                                                                                 if(consoletext[0][j]=='\0')alldone=1;
3994                                                                         }
3995                                                                         mapname[j-startpoint]='\0';
3996
3997                                                                         bodyprop=atof(mapname);
3998
3999                                                                         j++;
4000                                                                         startpoint=j;
4001                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4002                                                                                 mapname[j-startpoint]=consoletext[0][j];
4003                                                                                 j++;
4004                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4005                                                                         }
4006                                                                         mapname[j-startpoint]='\0';
4007
4008                                                                         armprop=atof(mapname);
4009
4010                                                                         j++;
4011                                                                         startpoint=j;
4012                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4013                                                                                 mapname[j-startpoint]=consoletext[0][j];
4014                                                                                 j++;
4015                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4016                                                                         }
4017                                                                         mapname[j-startpoint]='\0';
4018
4019                                                                         legprop=atof(mapname);
4020
4021                                                                         if(player[closest].creature==wolftype){
4022                                                                                 player[closest].proportionhead=1.1*headprop;
4023                                                                                 player[closest].proportionbody=1.1*bodyprop;
4024                                                                                 player[closest].proportionarms=1.1*armprop;
4025                                                                                 player[closest].proportionlegs=1.1*legprop;
4026                                                                         }
4027
4028                                                                         if(player[closest].creature==rabbittype){
4029                                                                                 player[closest].proportionhead=1.2*headprop;
4030                                                                                 player[closest].proportionbody=1.05*bodyprop;
4031                                                                                 player[closest].proportionarms=1.00*armprop;
4032                                                                                 player[closest].proportionlegs=1.1*legprop;
4033                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4034                                                                         }
4035
4036                                                                         donesomething=1;
4037                                                         }
4038
4039
4040                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4041                                                                 for(i=1;i<numplayers;i++){
4042                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4043                                                                 }
4044
4045                                                                 donesomething=1;
4046                                                         }
4047
4048                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4049                                                                 for(j=9;j<consolechars[0];j++){
4050                                                                         mapname[j-9]=consoletext[0][j];
4051                                                                 }
4052
4053                                                                 tutoriallevel=atoi(mapname);
4054
4055                                                                 donesomething=1;
4056                                                         }
4057
4058
4059                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4060                                                                 for(j=6;j<consolechars[0];j++){
4061                                                                         mapname[j-6]=consoletext[0][j];
4062                                                                 }
4063
4064                                                                 tintg=atof(mapname);
4065
4066                                                                 donesomething=1;
4067                                                         }
4068
4069                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4070                                                                 for(j=6;j<consolechars[0];j++){
4071                                                                         mapname[j-6]=consoletext[0][j];
4072                                                                 }
4073
4074                                                                 tintb=atof(mapname);
4075
4076                                                                 donesomething=1;
4077                                                         }
4078
4079                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4080                                                                 for(j=8;j<consolechars[0];j++){
4081                                                                         mapname[j-8]=consoletext[0][j];
4082                                                                 }
4083
4084                                                                 hostile=atoi(mapname);
4085
4086                                                                 donesomething=1;
4087                                                         }
4088
4089
4090                                                         if(Compare(consoletext[0],"type active ",0,11)){
4091                                                                 editoractive=typeactive;
4092
4093                                                                 donesomething=1;
4094                                                         }
4095
4096                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4097                                                                 indemo=1;
4098                                                                 hotspot[numhotspots]=player[0].coords;
4099                                                                 hotspotsize[numhotspots]=0;
4100                                                                 hotspottype[numhotspots]=-111;
4101                                                                 mapname[0]='\0';
4102                                                                 strcpy(hotspottext[numhotspots],"mapname");
4103                                                                 numhotspots++;
4104
4105                                                                 donesomething=1;
4106                                                         }
4107
4108                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4109                                                                 indemo=0;
4110                                                                 numhotspots--;
4111
4112                                                                 donesomething=1;
4113                                                         }
4114
4115                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4116                                                                 editoractive=typesitting;
4117
4118                                                                 donesomething=1;
4119                                                         }
4120
4121                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4122                                                                 editoractive=typesittingwall;
4123
4124                                                                 donesomething=1;
4125                                                         }
4126
4127                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4128                                                                 editoractive=typesleeping;
4129
4130                                                                 donesomething=1;
4131                                                         }
4132                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4133                                                                 editoractive=typedead1;
4134
4135                                                                 donesomething=1;
4136                                                         }
4137                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4138                                                                 editoractive=typedead2;
4139
4140                                                                 donesomething=1;
4141                                                         }
4142                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4143                                                                 editoractive=typedead3;
4144                                                                 donesomething=1;
4145                                                         }
4146                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4147                                                                 editoractive=typedead4;
4148
4149                                                                 donesomething=1;
4150                                                         }
4151
4152                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4153                                                                 editorpathtype=wpkeepwalking;
4154
4155                                                                 donesomething=1;
4156                                                         }
4157
4158                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4159                                                                 editorpathtype=wppause;
4160
4161                                                                 donesomething=1;
4162                                                         }
4163
4164                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4165                                                                 maptype=mapkilleveryone;
4166
4167                                                                 donesomething=1;
4168                                                         }
4169
4170                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4171                                                                 maptype=mapgosomewhere;
4172
4173                                                                 donesomething=1;
4174                                                         }
4175
4176                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4177                                                                 maptype=mapkillsomeone;
4178
4179                                                                 donesomething=1;
4180
4181                                                         }
4182
4183                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4184                                                                 maptype=mapkillmost;
4185
4186                                                                 donesomething=1;
4187
4188                                                         }
4189
4190                                                         if(Compare(consoletext[0],"hs ",0,2)){
4191                                                                 int startpoint;
4192                                                                 int alldone;
4193
4194                                                                 hotspot[numhotspots]=player[0].coords;
4195
4196                                                                 alldone=0;
4197                                                                 startpoint=3;
4198                                                                 j=startpoint;
4199                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4200                                                                         mapname[j-startpoint]=consoletext[0][j];
4201                                                                         j++;
4202                                                                         if(consoletext[0][j]=='\0')alldone=1;
4203                                                                 }
4204                                                                 mapname[j-startpoint]='\0';
4205
4206                                                                 hotspotsize[numhotspots]=atof(mapname);
4207
4208                                                                 j++;
4209                                                                 startpoint=j;
4210                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4211                                                                         mapname[j-startpoint]=consoletext[0][j];
4212                                                                         j++;
4213                                                                         if(consoletext[0][j]=='\0')alldone=1;
4214                                                                 }
4215                                                                 mapname[j-startpoint]='\0';
4216
4217                                                                 hotspottype[numhotspots]=atoi(mapname);
4218
4219                                                                 j++;
4220                                                                 startpoint=j;
4221                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4222                                                                         mapname[j-startpoint]=consoletext[0][j];
4223                                                                         j++;
4224                                                                         if(consoletext[0][j]=='\0')alldone=1;
4225                                                                 }
4226                                                                 mapname[j-startpoint]='\n';
4227                                                                 mapname[j-startpoint+1]='\0';
4228
4229                                                                 strcpy(hotspottext[numhotspots],mapname);
4230
4231                                                                 numhotspots++;
4232
4233                                                                 donesomething=1;
4234                                                         }
4235
4236                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4237                                                                 int startpoint;
4238                                                                 int alldone;
4239
4240                                                                 alldone=0;
4241                                                                 startpoint=9;
4242                                                                 j=startpoint;
4243                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4244                                                                         mapname[j-startpoint]=consoletext[0][j];
4245                                                                         j++;
4246                                                                         if(consoletext[0][j]=='\0')alldone=1;
4247                                                                 }
4248                                                                 mapname[j-startpoint]='\0';
4249                                                                 startpoint=j+1;
4250
4251                                                                 dialoguetype[numdialogues]=atoi(mapname);
4252
4253                                                                 mapname[0]=':';
4254                                                                 mapname[1]='D';
4255                                                                 mapname[2]='a';
4256                                                                 mapname[3]='t';
4257                                                                 mapname[4]='a';
4258                                                                 mapname[5]=':';
4259                                                                 mapname[6]='D';
4260                                                                 mapname[7]='i';
4261                                                                 mapname[8]='a';
4262                                                                 mapname[9]='l';
4263                                                                 mapname[10]='o';
4264                                                                 mapname[11]='g';
4265                                                                 mapname[12]='u';
4266                                                                 mapname[13]='e';
4267                                                                 mapname[14]='s';
4268                                                                 mapname[15]=':';
4269                                                                 for(j=startpoint;j<consolechars[0];j++){
4270                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4271                                                                 }
4272                                                                 mapname[consolechars[0]-startpoint+16]='.';
4273                                                                 mapname[consolechars[0]-startpoint+17]='t';
4274                                                                 mapname[consolechars[0]-startpoint+18]='x';
4275                                                                 mapname[consolechars[0]-startpoint+19]='t';
4276                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4277
4278                                                                 for(j=0;j<max_dialoguelength;j++){
4279                                                                         for(k=0;k<128;k++){
4280                                                                                 dialoguetext[numdialogues][j][k]='\0';
4281                                                                         }
4282                                                                         for(k=0;k<64;k++){
4283                                                                                 dialoguename[numdialogues][j][k]='\0';
4284                                                                         }
4285                                                                 }
4286
4287                                                                 ifstream ipstream(ConvertFileName(mapname));
4288                                                                 ipstream.ignore(256,':');
4289                                                                 ipstream >> numdialogueboxes[numdialogues];
4290                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4291                                                                         ipstream.ignore(256,':');
4292                                                                         ipstream.ignore(256,':');
4293                                                                         ipstream.ignore(256,' ');
4294                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4295                                                                         ipstream.ignore(256,':');
4296                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4297                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4298                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4299                                                                         ipstream.ignore(256,':');
4300                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4301                                                                         ipstream.ignore(256,':');
4302                                                                         ipstream.ignore(256,' ');
4303                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4304                                                                         for(j=0;j<128;j++){
4305                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4306                                                                         }
4307                                                                         ipstream.ignore(256,':');
4308                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4309                                                                 }
4310
4311                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4312                                                                         for(j=0;j<numplayers;j++){
4313                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4314                                                                         }
4315                                                                 }
4316                                                                 ipstream.close();
4317
4318                                                                 directing=1;
4319                                                                 indialogue=0;
4320                                                                 whichdialogue=numdialogues;
4321
4322
4323                                                                 numdialogues++;
4324
4325                                                                 donesomething=1;
4326                                                         }
4327
4328                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4329                                                                 int startpoint;
4330                                                                 int alldone;
4331                                                                 int whichdi;
4332
4333                                                                 alldone=0;
4334                                                                 startpoint=12;
4335                                                                 j=startpoint;
4336                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4337                                                                         mapname[j-startpoint]=consoletext[0][j];
4338                                                                         j++;
4339                                                                         if(consoletext[0][j]=='\0')alldone=1;
4340                                                                 }
4341                                                                 mapname[j-startpoint]='\0';
4342                                                                 startpoint=j+1;
4343
4344                                                                 whichdi=atoi(mapname);
4345
4346                                                                 mapname[0]=':';
4347                                                                 mapname[1]='D';
4348                                                                 mapname[2]='a';
4349                                                                 mapname[3]='t';
4350                                                                 mapname[4]='a';
4351                                                                 mapname[5]=':';
4352                                                                 mapname[6]='D';
4353                                                                 mapname[7]='i';
4354                                                                 mapname[8]='a';
4355                                                                 mapname[9]='l';
4356                                                                 mapname[10]='o';
4357                                                                 mapname[11]='g';
4358                                                                 mapname[12]='u';
4359                                                                 mapname[13]='e';
4360                                                                 mapname[14]='s';
4361                                                                 mapname[15]=':';
4362                                                                 for(j=startpoint;j<consolechars[0];j++){
4363                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4364                                                                 }
4365                                                                 mapname[consolechars[0]-startpoint+16]='.';
4366                                                                 mapname[consolechars[0]-startpoint+17]='t';
4367                                                                 mapname[consolechars[0]-startpoint+18]='x';
4368                                                                 mapname[consolechars[0]-startpoint+19]='t';
4369                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4370
4371                                                                 for(j=0;j<max_dialoguelength;j++){
4372                                                                         for(k=0;k<128;k++){
4373                                                                                 dialoguetext[whichdi][j][k]='\0';
4374                                                                         }
4375                                                                         for(k=0;k<64;k++){
4376                                                                                 dialoguename[whichdi][j][k]='\0';
4377                                                                         }
4378                                                                 }
4379
4380                                                                 ifstream ipstream(ConvertFileName(mapname));
4381                                                                 ipstream.ignore(256,':');
4382                                                                 ipstream >> numdialogueboxes[whichdi];
4383                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4384                                                                         ipstream.ignore(256,':');
4385                                                                         ipstream.ignore(256,':');
4386                                                                         ipstream.ignore(256,' ');
4387                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4388                                                                         ipstream.ignore(256,':');
4389                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4390                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4391                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4392                                                                         ipstream.ignore(256,':');
4393                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4394                                                                         ipstream.ignore(256,':');
4395                                                                         ipstream.ignore(256,' ');
4396                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4397                                                                         for(j=0;j<128;j++){
4398                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4399                                                                         }
4400                                                                         ipstream.ignore(256,':');
4401                                                                         ipstream >> dialogueboxsound[whichdi][i];
4402                                                                 }
4403
4404                                                                 ipstream.close();
4405
4406                                                                 donesomething=1;
4407                                                         }
4408
4409                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4410                                                                 int startpoint;
4411                                                                 int alldone;
4412                                                                 int whichdi;
4413
4414                                                                 alldone=0;
4415                                                                 startpoint=8;
4416                                                                 j=startpoint;
4417                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4418                                                                         mapname[j-startpoint]=consoletext[0][j];
4419                                                                         j++;
4420                                                                         if(consoletext[0][j]=='\0')alldone=1;
4421                                                                 }
4422                                                                 mapname[j-startpoint]='\0';
4423                                                                 dialoguetype[0]=atoi(mapname);
4424
4425                                                                 startpoint=j+1;
4426
4427                                                                 donesomething=1;
4428                                                         }
4429
4430
4431                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4432                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4433
4434                                                                 donesomething=1;
4435                                                         }
4436
4437                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4438                                                                 numdialogues--;
4439                                                                 if(numdialogues<0)numdialogues=0;
4440
4441                                                                 donesomething=1;
4442                                                         }
4443
4444                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4445                                                                 player[0].immobile=1;
4446                                                                 donesomething=1;
4447                                                         }
4448
4449                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4450                                                                 player[0].immobile=0;
4451                                                                 donesomething=1;
4452                                                         }
4453
4454                                                         if(Compare(consoletext[0],"play ",0,4)){
4455                                                                 int startpoint;
4456                                                                 int alldone;
4457
4458                                                                 alldone=0;
4459                                                                 startpoint=5;
4460                                                                 j=startpoint;
4461                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4462                                                                         mapname[j-startpoint]=consoletext[0][j];
4463                                                                         j++;
4464                                                                         if(consoletext[0][j]=='\0')alldone=1;
4465                                                                 }
4466                                                                 mapname[j-startpoint]='\0';
4467                                                                 startpoint=j+1;
4468
4469                                                                 whichdialogue=atoi(mapname);
4470
4471                                                                 if(numdialogues>whichdialogue){
4472                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4473                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4474                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4475                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4476                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4477                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4478                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4479                                                                         }
4480
4481                                                                         directing=0;
4482                                                                         indialogue=0;
4483
4484                                                                         donesomething=1;
4485
4486                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4487                                                                         float gLoc[3];
4488                                                                         float vel[3];
4489                                                                         XYZ temppos;
4490                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4491                                                                         temppos=temppos-viewer;
4492                                                                         Normalise(&temppos);
4493                                                                         temppos+=viewer;
4494
4495                                                                         gLoc[0]=temppos.x;
4496                                                                         gLoc[1]=temppos.y;
4497                                                                         gLoc[2]=temppos.z;
4498                                                                         vel[0]=0;
4499                                                                         vel[1]=0;
4500                                                                         vel[2]=0;
4501                                                                         int whichsoundplay;
4502                                                                         whichsoundplay=rabbitchitter;
4503                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4504                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4505                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4506                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4507                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4508                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4509                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4510                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4511                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4512                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4513                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4514                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4515                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4516                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4517                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4518                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4519                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4520                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4521                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4522                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4523                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4524                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
4525                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
4526                                                                         //}
4527                                                                 }
4528                                                         }
4529
4530
4531
4532
4533                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4534                                                                 numhotspots--;
4535                                                                 if(numhotspots<0)numhotspots=0;
4536                                                                 donesomething=1;
4537                                                         }
4538
4539
4540                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4541                                                                 int startpoint;
4542                                                                 int alldone;
4543
4544                                                                 alldone=0;
4545                                                                 startpoint=11;
4546                                                                 j=startpoint;
4547                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4548                                                                         mapname[j-startpoint]=consoletext[0][j];
4549                                                                         j++;
4550                                                                         if(consoletext[0][j]=='\0')alldone=1;
4551                                                                 }
4552                                                                 mapname[j-startpoint]='\0';
4553
4554                                                                 headprop=atof(mapname);
4555
4556                                                                 j++;
4557                                                                 startpoint=j;
4558                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4559                                                                         mapname[j-startpoint]=consoletext[0][j];
4560                                                                         j++;
4561                                                                         if(consoletext[0][j]=='\0')alldone=1;
4562                                                                 }
4563                                                                 mapname[j-startpoint]='\0';
4564
4565                                                                 bodyprop=atof(mapname);
4566
4567                                                                 j++;
4568                                                                 startpoint=j;
4569                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4570                                                                         mapname[j-startpoint]=consoletext[0][j];
4571                                                                         j++;
4572                                                                         if(consoletext[0][j]=='\0')alldone=1;
4573                                                                 }
4574                                                                 mapname[j-startpoint]='\0';
4575
4576                                                                 armprop=atof(mapname);
4577
4578                                                                 j++;
4579                                                                 startpoint=j;
4580                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4581                                                                         mapname[j-startpoint]=consoletext[0][j];
4582                                                                         j++;
4583                                                                         if(consoletext[0][j]=='\0')alldone=1;
4584                                                                 }
4585                                                                 mapname[j-startpoint]='\0';
4586
4587                                                                 legprop=atof(mapname);
4588
4589                                                                 if(player[0].creature==wolftype){
4590                                                                         player[0].proportionhead=1.1*headprop;
4591                                                                         player[0].proportionbody=1.1*bodyprop;
4592                                                                         player[0].proportionarms=1.1*armprop;
4593                                                                         player[0].proportionlegs=1.1*legprop;
4594                                                                 }
4595
4596                                                                 if(player[0].creature==rabbittype){
4597                                                                         player[0].proportionhead=1.2*headprop;
4598                                                                         player[0].proportionbody=1.05*bodyprop;
4599                                                                         player[0].proportionarms=1.00*armprop;
4600                                                                         player[0].proportionlegs=1.1*legprop;
4601                                                                         player[0].proportionlegs.y=1.05*legprop;
4602                                                                 }
4603
4604                                                                 donesomething=1;
4605                                                         }
4606
4607                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4608                                                                 for(i=0;i<numplayers;i++){
4609                                                                         if(i>0)player[i].immobile=1;
4610                                                                 }
4611                                                                 donesomething=1;
4612                                                         }
4613
4614
4615                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4616                                                                 player[0].armorhead=1;
4617                                                                 player[0].armorhigh=1;
4618                                                                 player[0].armorlow=1;
4619                                                                 player[0].protectionhead=1;
4620                                                                 player[0].protectionhigh=1;
4621                                                                 player[0].protectionlow=1;
4622                                                                 player[0].metalhead=1;
4623                                                                 player[0].metalhigh=1;
4624                                                                 player[0].metallow=1;
4625                                                                 player[0].power=1;
4626                                                                 player[0].speedmult=1;
4627                                                                 player[0].scale=1;
4628
4629                                                                 if(player[0].creature==wolftype){
4630                                                                         player[0].proportionhead=1.1;
4631                                                                         player[0].proportionbody=1.1;
4632                                                                         player[0].proportionarms=1.1;
4633                                                                         player[0].proportionlegs=1.1;
4634                                                                 }
4635
4636                                                                 if(player[0].creature==rabbittype){
4637                                                                         player[0].proportionhead=1.2;
4638                                                                         player[0].proportionbody=1.05;
4639                                                                         player[0].proportionarms=1.00;
4640                                                                         player[0].proportionlegs=1.1;
4641                                                                         player[0].proportionlegs.y=1.05;
4642                                                                 }
4643
4644                                                                 player[0].numclothes=0;
4645                                                                 if(player[0].whichskin==0){
4646                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4647                                                                 }
4648                                                                 else if(player[0].whichskin==1){
4649                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4650                                                                 }
4651                                                                 else if(player[0].whichskin==2){
4652                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4653                                                                 }
4654                                                                 else if(player[0].whichskin==3){
4655                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4656                                                                 }
4657                                                                 else if(player[0].whichskin==4){
4658                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4659                                                                 }
4660                                                                 else if(player[0].whichskin==5){
4661                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4662                                                                 }
4663                                                                 else if(player[0].whichskin==6){
4664                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4665                                                                 }
4666                                                                 else if(player[0].whichskin==7){
4667                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4668                                                                 }
4669                                                                 else if(player[0].whichskin==8){
4670                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4671                                                                 }
4672                                                                 else if(player[0].whichskin==9){
4673                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4674                                                                 }
4675
4676                                                                 editoractive=typeactive;
4677                                                                 player[0].immobile=0;
4678
4679
4680
4681                                                                 donesomething=1;
4682                                                         }
4683
4684                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4685                                                                 int startpoint;
4686                                                                 int alldone;
4687                                                                 alldone=0;
4688                                                                 startpoint=5;
4689                                                                 j=startpoint;
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                                                                 tintr=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                                                                 tintg=atof(mapname);
4709
4710                                                                 j++;
4711                                                                 startpoint=j;
4712                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4713                                                                         mapname[j-startpoint]=consoletext[0][j];
4714                                                                         j++;
4715                                                                         if(consoletext[0][j]=='\0')alldone=1;
4716                                                                 }
4717                                                                 mapname[j-startpoint]='\0';
4718
4719                                                                 tintb=atof(mapname);
4720
4721                                                                 donesomething=1;
4722                                                         }
4723
4724                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
4725                                                                 int startpoint;
4726                                                                 int alldone;
4727                                                                 alldone=0;
4728                                                                 startpoint=9;
4729                                                                 j=startpoint;
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                                                                 skyboxr=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                                                                 skyboxg=atof(mapname);
4749
4750                                                                 j++;
4751                                                                 startpoint=j;
4752                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4753                                                                         mapname[j-startpoint]=consoletext[0][j];
4754                                                                         j++;
4755                                                                         if(consoletext[0][j]=='\0')alldone=1;
4756                                                                 }
4757                                                                 mapname[j-startpoint]='\0';
4758
4759                                                                 skyboxb=atof(mapname);
4760
4761                                                                 skyboxlightr=skyboxr;
4762                                                                 skyboxlightg=skyboxg;
4763                                                                 skyboxlightb=skyboxb;
4764
4765                                                                 SetUpLighting();
4766
4767                                                                 //if(skyboxtexture){
4768                                                                 terrain.DoShadows();
4769                                                                 objects.DoShadows();
4770                                                                 /*}
4771                                                                 else terrain.DoLighting();
4772                                                                 */
4773                                                                 donesomething=1;
4774                                                         }
4775
4776                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
4777                                                                 int startpoint;
4778                                                                 int alldone;
4779                                                                 alldone=0;
4780                                                                 startpoint=10;
4781                                                                 j=startpoint;
4782                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4783                                                                         mapname[j-startpoint]=consoletext[0][j];
4784                                                                         j++;
4785                                                                         if(consoletext[0][j]=='\0')alldone=1;
4786                                                                 }
4787                                                                 mapname[j-startpoint]='\0';
4788
4789                                                                 skyboxlightr=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                                                                 skyboxlightg=atof(mapname);
4801
4802                                                                 j++;
4803                                                                 startpoint=j;
4804                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4805                                                                         mapname[j-startpoint]=consoletext[0][j];
4806                                                                         j++;
4807                                                                         if(consoletext[0][j]=='\0')alldone=1;
4808                                                                 }
4809                                                                 mapname[j-startpoint]='\0';
4810
4811                                                                 skyboxlightb=atof(mapname);
4812
4813                                                                 SetUpLighting();
4814
4815                                                                 //if(skyboxtexture){
4816                                                                 terrain.DoShadows();
4817                                                                 objects.DoShadows();
4818                                                                 /*}
4819                                                                 else terrain.DoLighting();
4820                                                                 */
4821                                                                 donesomething=1;
4822                                                         }
4823
4824                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
4825                                                                 skyboxtexture=1-skyboxtexture;
4826
4827                                                                 SetUpLighting();
4828                                                                 //if(skyboxtexture){
4829                                                                 terrain.DoShadows();
4830                                                                 objects.DoShadows();
4831                                                                 /*}
4832                                                                 else terrain.DoLighting();
4833                                                                 */
4834                                                                 donesomething=1;
4835                                                         }
4836
4837                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
4838                                                                 int startpoint;
4839                                                                 int alldone;
4840                                                                 alldone=0;
4841                                                                 startpoint=11;
4842                                                                 j=startpoint;
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].protectionhead=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].protectionhigh=atof(mapname);
4862
4863                                                                 j++;
4864                                                                 startpoint=j;
4865                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4866                                                                         mapname[j-startpoint]=consoletext[0][j];
4867                                                                         j++;
4868                                                                         if(consoletext[0][j]=='\0')alldone=1;
4869                                                                 }
4870                                                                 mapname[j-startpoint]='\0';
4871
4872                                                                 player[0].protectionlow=atof(mapname);
4873
4874                                                                 donesomething=1;
4875                                                         }
4876
4877                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
4878                                                                 int startpoint;
4879                                                                 int alldone;
4880                                                                 alldone=0;
4881                                                                 startpoint=6;
4882                                                                 j=startpoint;
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].armorhead=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].armorhigh=atof(mapname);
4902
4903                                                                 j++;
4904                                                                 startpoint=j;
4905                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4906                                                                         mapname[j-startpoint]=consoletext[0][j];
4907                                                                         j++;
4908                                                                         if(consoletext[0][j]=='\0')alldone=1;
4909                                                                 }
4910                                                                 mapname[j-startpoint]='\0';
4911
4912                                                                 player[0].armorlow=atof(mapname);
4913
4914                                                                 donesomething=1;
4915                                                         }
4916
4917                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
4918                                                                 for(i=0;i<numplayers;i++){
4919                                                                         player[i].protectionhead=1.0;
4920                                                                         player[i].protectionhigh=1.0;
4921                                                                         player[i].protectionlow=1.0;
4922                                                                         player[i].armorhead=1.0;
4923                                                                         player[i].armorhigh=1.0;
4924                                                                         player[i].armorlow=1.0;
4925                                                                 }
4926
4927                                                                 donesomething=1;
4928                                                         }
4929
4930                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
4931                                                                 int closest=-1;
4932                                                                 float closestdist=-1;
4933                                                                 float distance;
4934                                                                 if(numplayers>1)
4935                                                                         for(i=1;i<numplayers;i++){
4936                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4937                                                                                 if(closestdist==-1||distance<closestdist){
4938                                                                                         closestdist=distance;
4939                                                                                         closest=i;
4940                                                                                 }
4941                                                                         }
4942
4943                                                                         int startpoint;
4944                                                                         int alldone;
4945                                                                         alldone=0;
4946                                                                         startpoint=15;
4947                                                                         j=startpoint;
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].protectionhead=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].protectionhigh=atof(mapname);
4967
4968                                                                         j++;
4969                                                                         startpoint=j;
4970                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4971                                                                                 mapname[j-startpoint]=consoletext[0][j];
4972                                                                                 j++;
4973                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4974                                                                         }
4975                                                                         mapname[j-startpoint]='\0';
4976
4977                                                                         player[closest].protectionlow=atof(mapname);
4978
4979                                                                         donesomething=1;
4980                                                         }
4981
4982                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
4983                                                                 int closest=-1;
4984                                                                 float closestdist=-1;
4985                                                                 float distance;
4986                                                                 if(numplayers>1)
4987                                                                         for(i=1;i<numplayers;i++){
4988                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4989                                                                                 if(closestdist==-1||distance<closestdist){
4990                                                                                         closestdist=distance;
4991                                                                                         closest=i;
4992                                                                                 }
4993                                                                         }
4994                                                                         int startpoint;
4995                                                                         int alldone;
4996                                                                         alldone=0;
4997                                                                         startpoint=10;
4998                                                                         j=startpoint;
4999                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5000                                                                                 mapname[j-startpoint]=consoletext[0][j];
5001                                                                                 j++;
5002                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5003                                                                         }
5004                                                                         mapname[j-startpoint]='\0';
5005
5006                                                                         player[closest].armorhead=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].armorhigh=atof(mapname);
5018
5019                                                                         j++;
5020                                                                         startpoint=j;
5021                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5022                                                                                 mapname[j-startpoint]=consoletext[0][j];
5023                                                                                 j++;
5024                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5025                                                                         }
5026                                                                         mapname[j-startpoint]='\0';
5027
5028                                                                         player[closest].armorlow=atof(mapname);
5029
5030                                                                         donesomething=1;
5031                                                         }
5032
5033
5034                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5035                                                                 int startpoint;
5036                                                                 int alldone;
5037                                                                 alldone=0;
5038                                                                 startpoint=6;
5039                                                                 j=startpoint;
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].metalhead=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                                                                 mapname[j-startpoint]='\0';
5057
5058                                                                 player[0].metalhigh=atof(mapname);
5059
5060                                                                 j++;
5061                                                                 startpoint=j;
5062                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5063                                                                         mapname[j-startpoint]=consoletext[0][j];
5064                                                                         j++;
5065                                                                         if(consoletext[0][j]=='\0')alldone=1;
5066                                                                 }
5067
5068                                                                 mapname[j-startpoint]='\0';
5069
5070                                                                 player[0].metallow=atof(mapname);
5071
5072                                                                 donesomething=1;
5073                                                         }
5074
5075                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5076                                                                 int closest=-1;
5077                                                                 float closestdist=-1;
5078                                                                 float distance;
5079                                                                 if(numplayers>1)
5080                                                                         for(i=1;i<numplayers;i++){
5081                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5082                                                                                 if(closestdist==-1||distance<closestdist){
5083                                                                                         closestdist=distance;
5084                                                                                         closest=i;
5085                                                                                 }
5086                                                                         }
5087                                                                         player[closest].numclothes=0;
5088                                                                         if(player[closest].whichskin==0){
5089                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5090                                                                         }
5091                                                                         else if(player[closest].whichskin==1){
5092                                                                                 LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5093                                                                         }
5094                                                                         else if(player[closest].whichskin==2){
5095                                                                                 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5096                                                                         }
5097                                                                         else if(player[closest].whichskin==3){
5098                                                                                 LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5099                                                                         }
5100                                                                         else if(player[closest].whichskin==4){
5101                                                                                 LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5102                                                                         }
5103                                                                         else if(player[closest].whichskin==5){
5104                                                                                 LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5105                                                                         }
5106                                                                         else if(player[closest].whichskin==6){
5107                                                                                 LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5108                                                                         }
5109                                                                         else if(player[closest].whichskin==7){
5110                                                                                 LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5111                                                                         }
5112                                                                         else if(player[closest].whichskin==8){
5113                                                                                 LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5114                                                                         }
5115                                                                         else if(player[closest].whichskin==9){
5116                                                                                 LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5117                                                                         }
5118
5119                                                                         donesomething=1;
5120                                                         }
5121
5122                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5123                                                                 int closest=0;
5124
5125                                                                 player[closest].numclothes=0;
5126                                                                 if(player[closest].whichskin==0){
5127                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5128                                                                 }
5129                                                                 else if(player[closest].whichskin==1){
5130                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5131                                                                 }
5132                                                                 else if(player[closest].whichskin==2){
5133                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5134                                                                 }
5135                                                                 else if(player[closest].whichskin==3){
5136                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5137                                                                 }
5138                                                                 else if(player[closest].whichskin==4){
5139                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5140                                                                 }
5141                                                                 else if(player[closest].whichskin==5){
5142                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5143                                                                 }
5144                                                                 else if(player[closest].whichskin==6){
5145                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5146                                                                 }
5147                                                                 else if(player[closest].whichskin==7){
5148                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5149                                                                 }
5150                                                                 else if(player[closest].whichskin==8){
5151                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5152                                                                 }
5153                                                                 else if(player[closest].whichskin==9){
5154                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5155                                                                 }
5156
5157                                                                 donesomething=1;
5158                                                         }
5159
5160                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5161                                                                 mapname[0]=':';
5162                                                                 mapname[1]='D';
5163                                                                 mapname[2]='a';
5164                                                                 mapname[3]='t';
5165                                                                 mapname[4]='a';
5166                                                                 mapname[5]=':';
5167                                                                 mapname[6]='T';
5168                                                                 mapname[7]='e';
5169                                                                 mapname[8]='x';
5170                                                                 mapname[9]='t';
5171                                                                 mapname[10]='u';
5172                                                                 mapname[11]='r';
5173                                                                 mapname[12]='e';
5174                                                                 mapname[13]='s';
5175                                                                 mapname[14]=':';
5176                                                                 for(j=8;j<consolechars[0];j++){
5177                                                                         mapname[j-8+15]=consoletext[0][j];
5178                                                                 }
5179                                                                 mapname[consolechars[0]-8+15]='.';
5180                                                                 mapname[consolechars[0]-8+16]='p';
5181                                                                 mapname[consolechars[0]-8+17]='n';
5182                                                                 mapname[consolechars[0]-8+18]='g';
5183                                                                 mapname[consolechars[0]-8+19]='\0';
5184
5185                                                                 //:Data:Textures:Pants.png
5186
5187                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5188                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5189                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5190                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5191                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5192                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5193                                                                         player[0].numclothes++;
5194                                                                 }
5195
5196                                                                 donesomething=1;
5197                                                         }
5198
5199                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5200                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5201
5202                                                                 donesomething=1;
5203                                                         }
5204
5205                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5206                                                                 cellophane=1-cellophane;
5207
5208                                                                 if(cellophane){
5209                                                                         for(i=0;i<numplayers;i++){
5210                                                                                 player[i].proportionhead.z=0;
5211                                                                                 player[i].proportionbody.z=0;
5212                                                                                 player[i].proportionarms.z=0;
5213                                                                                 player[i].proportionlegs.z=0;
5214                                                                         }
5215                                                                 }
5216
5217                                                                 if(!cellophane){
5218                                                                         for(i=0;i<numplayers;i++){
5219                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5220                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5221                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5222                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5223                                                                         }
5224                                                                 }
5225
5226                                                                 donesomething=1;
5227                                                         }
5228
5229                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5230                                                                 mapname[0]=':';
5231                                                                 mapname[1]='D';
5232                                                                 mapname[2]='a';
5233                                                                 mapname[3]='t';
5234                                                                 mapname[4]='a';
5235                                                                 mapname[5]=':';
5236                                                                 mapname[6]='T';
5237                                                                 mapname[7]='e';
5238                                                                 mapname[8]='x';
5239                                                                 mapname[9]='t';
5240                                                                 mapname[10]='u';
5241                                                                 mapname[11]='r';
5242                                                                 mapname[12]='e';
5243                                                                 mapname[13]='s';
5244                                                                 mapname[14]=':';
5245                                                                 for(j=12;j<consolechars[0];j++){
5246                                                                         mapname[j-12+15]=consoletext[0][j];
5247                                                                 }
5248                                                                 mapname[consolechars[0]-12+15]='.';
5249                                                                 mapname[consolechars[0]-12+16]='p';
5250                                                                 mapname[consolechars[0]-12+17]='n';
5251                                                                 mapname[consolechars[0]-12+18]='g';
5252                                                                 mapname[consolechars[0]-12+19]='\0';
5253
5254                                                                 //:Data:Textures:Pants.png
5255                                                                 int closest=-1;
5256                                                                 float closestdist=-1;
5257                                                                 float distance;
5258                                                                 if(numplayers>1)
5259                                                                         for(i=1;i<numplayers;i++){
5260                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5261                                                                                 if(closestdist==-1||distance<closestdist){
5262                                                                                         closestdist=distance;
5263                                                                                         closest=i;
5264                                                                                 }
5265                                                                         }
5266
5267                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5268                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5269                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5270                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5271                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5272                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5273                                                                                 player[closest].numclothes++;
5274                                                                         }
5275
5276                                                                         donesomething=1;
5277                                                         }
5278
5279                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5280                                                                 player[0].skeleton.id=0;
5281                                                                 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);
5282                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5283                                                                 player[0].creature=rabbittype;
5284                                                                 player[0].scale=.2;
5285
5286                                                                 player[0].proportionhead=1.2;
5287                                                                 player[0].proportionbody=1.05;
5288                                                                 player[0].proportionarms=1.00;
5289                                                                 player[0].proportionlegs=1.1;
5290                                                                 player[0].proportionlegs.y=1.05;
5291                                                                 player[0].headless=0;
5292
5293                                                                 player[0].damagetolerance=200;
5294
5295                                                                 donesomething=1;
5296                                                         }
5297                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5298                                                                 player[0].skeleton.id=0;
5299                                                                 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);
5300                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5301                                                                 player[0].creature=wolftype;
5302
5303                                                                 player[0].proportionhead=1.1;
5304                                                                 player[0].proportionbody=1.1;
5305                                                                 player[0].proportionarms=1.1;
5306                                                                 player[0].proportionlegs=1.1;
5307                                                                 player[0].proportionlegs.y=1.1;
5308                                                                 player[0].scale=.23;
5309
5310                                                                 player[0].damagetolerance=300;
5311
5312                                                                 donesomething=1;
5313                                                         }
5314                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5315                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5316                                                         donesomething=1;
5317                                                         }
5318                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5319                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5320                                                         donesomething=1;
5321                                                         }
5322                                                         if(Compare(consoletext[0],"david ",0,5)){
5323                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5324                                                         donesomething=1;
5325                                                         }*/
5326                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5327                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5328                                                                 donesomething=1;
5329                                                         }
5330                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5331                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5332                                                                 donesomething=1;
5333                                                         }
5334                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5335                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5336                                                                 donesomething=1;
5337                                                         }/*
5338                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5339                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5340                                                          donesomething=1;
5341                                                          }*/
5342                                                         if(Compare(consoletext[0],"white ",0,5)){
5343                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5344                                                                 donesomething=1;
5345                                                         }
5346                                                         if(Compare(consoletext[0],"brown ",0,5)){
5347                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5348                                                                 donesomething=1;
5349                                                         }
5350                                                         if(Compare(consoletext[0],"black ",0,5)){
5351                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5352                                                                 donesomething=1;
5353                                                         }
5354                                                         if(consolechars[0]>0){
5355                                                                 for(k=14;k>=1;k--){
5356                                                                         for(j=0;j<255;j++){
5357                                                                                 consoletext[k][j]=consoletext[k-1][j];
5358                                                                         }
5359                                                                         consolechars[k]=consolechars[k-1];
5360                                                                 }
5361                                                                 for(j=0;j<255;j++){
5362                                                                         consoletext[0][j]=' ';
5363                                                                 }
5364                                                                 consolechars[0]=0;
5365                                                                 consoleselected=0;
5366
5367                                                                 if(!donesomething){
5368                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
5369                                                                         OPENAL_SetVolume(channels[consolefailsound], 256);
5370                                                                         OPENAL_SetPaused(channels[consolefailsound], false);
5371                                                                 }
5372                                                         }
5373                                                 }
5374                                         }
5375                                         togglekey[i]=1;
5376                                 }
5377                                 else {
5378                                         togglekey[i]=0;
5379                                         togglekeydelay[i]=0;
5380                                 }
5381                         }
5382
5383                         consoleblinkdelay-=multiplier;
5384                         if(consoleblinkdelay<=0){
5385                                 consoleblinkdelay=.3;
5386                                 consoleblink=1-consoleblink;
5387                         }
5388                 }
5389
5390                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5391                         tryquit=1;
5392                         if(mainmenu==3){
5393                                 if(newdetail>2)newdetail=detail;
5394                                 if(newdetail<0)newdetail=detail;
5395                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5396                                 if(newscreenheight<0)newscreenheight=screenheight;
5397
5398                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5399                                 opstream << "Screenwidth:\n";
5400                                 opstream << newscreenwidth;
5401                                 opstream << "\nScreenheight:\n";
5402                                 opstream << newscreenheight;
5403                                 opstream << "\nMouse sensitivity:\n";
5404                                 opstream << usermousesensitivity;
5405                                 opstream << "\nBlur(0,1):\n";
5406                                 opstream << ismotionblur;
5407                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5408                                 opstream << newdetail;
5409                                 opstream << "\nFloating jump:\n";
5410                                 opstream << floatjump;
5411                                 opstream << "\nMouse jump:\n";
5412                                 opstream << mousejump;
5413                                 opstream << "\nAmbient sound:\n";
5414                                 opstream << ambientsound;
5415                                 opstream << "\nBlood (0,1,2):\n";
5416                                 opstream << bloodtoggle;
5417                                 opstream << "\nAuto slomo:\n";
5418                                 opstream << autoslomo;
5419                                 opstream << "\nFoliage:\n";
5420                                 opstream << foliage;
5421                                 opstream << "\nMusic:\n";
5422                                 opstream << musictoggle;
5423                                 opstream << "\nTrilinear:\n";
5424                                 opstream << trilinear;
5425                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5426                                 opstream << decals;
5427                                 opstream << "\nInvert mouse:\n";
5428                                 opstream << invertmouse;
5429                                 opstream << "\nGamespeed:\n";
5430                                 if(oldgamespeed==0)oldgamespeed=1;
5431                                 opstream << oldgamespeed;
5432                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5433                                 opstream << difficulty;
5434                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5435                                 opstream << damageeffects;
5436                                 opstream << "\nText:\n";
5437                                 opstream << texttoggle;
5438                                 opstream << "\nDebug:\n";
5439                                 opstream << debugmode;
5440                                 opstream << "\nVBL Sync:\n";
5441                                 opstream << vblsync;
5442                                 opstream << "\nShow Points:\n";
5443                                 opstream << showpoints;
5444                                 opstream << "\nAlways Blur:\n";
5445                                 opstream << alwaysblur;
5446                                 opstream << "\nImmediate mode (turn on on G5):\n";
5447                                 opstream << immediate;
5448                                 opstream << "\nVelocity blur:\n";
5449                                 opstream << velocityblur;
5450                             opstream << "\nVolume:\n";
5451                         opstream << volume;
5452                                 opstream << "\nForward key:\n";
5453                                 opstream << KeyToChar(forwardkey);
5454                                 opstream << "\nBack key:\n";
5455                                 opstream << KeyToChar(backkey);
5456                                 opstream << "\nLeft key:\n";
5457                                 opstream << KeyToChar(leftkey);
5458                                 opstream << "\nRight key:\n";
5459                                 opstream << KeyToChar(rightkey);
5460                                 opstream << "\nJump key:\n";
5461                                 opstream << KeyToChar(jumpkey);
5462                                 opstream << "\nCrouch key:\n";
5463                                 opstream << KeyToChar(crouchkey);
5464                                 opstream << "\nDraw key:\n";
5465                                 opstream << KeyToChar(drawkey);
5466                                 opstream << "\nThrow key:\n";
5467                                 opstream << KeyToChar(throwkey);
5468                                 opstream << "\nAttack key:\n";
5469                                 opstream << KeyToChar(attackkey);
5470                                 opstream << "\nChat key:\n";
5471                                 opstream << KeyToChar(chatkey);
5472                                 opstream.close();
5473                         }
5474                 }
5475
5476                 static int oldwinfreeze;
5477                 if(winfreeze&&!oldwinfreeze){
5478                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5479                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
5480                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
5481                         OPENAL_SetPaused(channels[consolesuccesssound], false);
5482                 }
5483                 if(winfreeze==0)oldwinfreeze=winfreeze;
5484                 else oldwinfreeze++;
5485
5486                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5487                         if(winfreeze)winfreeze=0;
5488                         oldjumpkeydown=1;
5489                 }
5490                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5491                         if(winfreeze){
5492                                 mainmenu=9;
5493                                 gameon=0;
5494                         }
5495                 }
5496                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5497                         oldjumpkeydown=1;
5498                 }
5499                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5500
5501                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5502
5503                         static bool oldbuttondialogue;
5504
5505                         if(indialogue!=-1)talkdelay=1;
5506                         talkdelay-=multiplier;
5507
5508                         if(talkdelay<=0)
5509                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5510                                         for(i=0;i<numdialogues;i++){
5511                                                 int realdialoguetype;
5512                                                 bool special;
5513                                                 if(dialoguetype[i]>49){
5514                                                         realdialoguetype=dialoguetype[i]-50;
5515                                                         special=1;
5516                                                 }
5517                                                 else if(dialoguetype[i]>39){
5518                                                         realdialoguetype=dialoguetype[i]-40;
5519                                                         special=1;
5520                                                 }
5521                                                 else if(dialoguetype[i]>29){
5522                                                         realdialoguetype=dialoguetype[i]-30;
5523                                                         special=1;
5524                                                 }
5525                                                 else if(dialoguetype[i]>19){
5526                                                         realdialoguetype=dialoguetype[i]-20;
5527                                                         special=1;
5528                                                 }
5529                                                 else if(dialoguetype[i]>9){
5530                                                         realdialoguetype=dialoguetype[i]-10;
5531                                                         special=1;
5532                                                 }
5533                                                 else {
5534                                                         realdialoguetype=dialoguetype[i];
5535                                                         special=0;
5536                                                 }
5537                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5538                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5539                                                                 whichdialogue=i;
5540                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5541                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5542                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5543                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5544                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5545                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5546                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5547                                                                 }
5548                                                                 directing=0;
5549                                                                 indialogue=0;
5550                                                                 dialoguetime=0;
5551                                                                 dialoguegonethrough[i]++;
5552                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5553                                                                         static float gLoc[3];
5554                                                                         static float vel[3];
5555                                                                         XYZ temppos;
5556                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5557                                                                         temppos=temppos-viewer;
5558                                                                         Normalise(&temppos);
5559                                                                         temppos+=viewer;
5560
5561                                                                         gLoc[0]=temppos.x;
5562                                                                         gLoc[1]=temppos.y;
5563                                                                         gLoc[2]=temppos.z;vel[0]=0;
5564                                                                         vel[1]=0;
5565                                                                         vel[2]=0;
5566                                                                         int whichsoundplay;
5567                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5568                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5569                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5570                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5571                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5572                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5573                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5574                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5575                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5576                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5577                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5578                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5579                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5580                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5581                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5582                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5583                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5584                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5585                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5586                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5587                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
5588                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5589                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
5590                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
5591                                                                 }
5592                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5593                                                         }
5594                                                 }
5595                                         }
5596
5597                                         windvar+=multiplier;
5598                                         smoketex+=multiplier;
5599                                         tutorialstagetime+=multiplier;
5600
5601                                         static float hotspotvisual[40];
5602                                         if(numhotspots){
5603                                                 XYZ hotspotsprite;
5604                                                 if(editorenabled)
5605                                                         for(i=0;i<numhotspots;i++)
5606                                                                 hotspotvisual[i]-=multiplier/320;
5607
5608                                                 for(i=0;i<numhotspots;i++){
5609                                                         //if(hotspottype[i]<=10)
5610                                                         while(hotspotvisual[i]<0){
5611                                                                 hotspotsprite=0;
5612                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5613                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5614                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5615                                                                 hotspotsprite+=hotspot[i];
5616                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5617                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5618                                                         }
5619                                                 }
5620
5621                                                 for(i=0;i<numhotspots;i++){
5622                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5623                                                                 hotspot[i]=player[hotspottype[i]].coords;
5624                                                         }
5625                                                 }
5626                                         }
5627
5628                                         //Tutorial
5629                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5630                                                 tutorialstage++;
5631                                                 tutorialsuccess=0;
5632                                                 if(tutorialstage<=1){
5633                                                         canattack=0;
5634                                                         cananger=0;
5635                                                         reversaltrain=0;
5636                                                 }
5637                                                 if(tutorialstage==1){
5638                                                         tutorialmaxtime=5;
5639                                                 }
5640                                                 if(tutorialstage==2){
5641                                                         tutorialmaxtime=2;
5642                                                 }
5643                                                 if(tutorialstage==3){
5644                                                         tutorialmaxtime=600;
5645                                                 }
5646                                                 if(tutorialstage==4){
5647                                                         tutorialmaxtime=1000;
5648                                                 }
5649                                                 if(tutorialstage==5){
5650                                                         tutorialmaxtime=600;
5651                                                 }
5652                                                 if(tutorialstage==6){
5653                                                         tutorialmaxtime=600;
5654                                                 }
5655                                                 if(tutorialstage==7){
5656                                                         tutorialmaxtime=600;
5657                                                 }
5658                                                 if(tutorialstage==8){
5659                                                         tutorialmaxtime=600;
5660                                                 }
5661                                                 if(tutorialstage==9){
5662                                                         tutorialmaxtime=600;
5663                                                 }
5664                                                 if(tutorialstage==10){
5665                                                         tutorialmaxtime=2;
5666                                                 }
5667                                                 if(tutorialstage==11){
5668                                                         tutorialmaxtime=1000;
5669                                                 }
5670                                                 if(tutorialstage==12){
5671                                                         tutorialmaxtime=1000;
5672                                                 }
5673                                                 if(tutorialstage==13){
5674                                                         tutorialmaxtime=2;
5675                                                 }
5676                                                 if(tutorialstage==14){
5677                                                         tutorialmaxtime=3;
5678
5679                                                         XYZ temp,temp2;
5680
5681                                                         temp.x=1011;
5682                                                         temp.y=84;
5683                                                         temp.z=491;
5684                                                         temp2.x=1025;
5685                                                         temp2.y=75;
5686                                                         temp2.z=447;
5687
5688                                                         player[1].coords=(temp+temp2)/2;
5689
5690                                                         float gLoc[3];
5691                                                         float vel[3];
5692                                                         gLoc[0]=player[1].coords.x;
5693                                                         gLoc[1]=player[1].coords.y;
5694                                                         gLoc[2]=player[1].coords.z;
5695                                                         vel[0]=0;
5696                                                         vel[1]=0;
5697                                                         vel[2]=0;
5698                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5699                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5700                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5701                                                         OPENAL_SetPaused(channels[fireendsound], false);
5702
5703                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5704                                                                 if(Random()%2==0){
5705                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5706                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5707                                                                         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;
5708                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5709                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5710                                                                 }
5711                                                         }
5712
5713                                                 }
5714                                                 if(tutorialstage==15){
5715                                                         tutorialmaxtime=500;
5716                                                 }
5717                                                 if(tutorialstage==16){
5718                                                         tutorialmaxtime=500;
5719                                                 }
5720                                                 if(tutorialstage==17){
5721                                                         tutorialmaxtime=500;
5722                                                 }
5723                                                 if(tutorialstage==18){
5724                                                         tutorialmaxtime=500;
5725                                                 }
5726                                                 if(tutorialstage==19){
5727                                                         tutorialstage=20;
5728                                                         //tutorialmaxtime=500;
5729                                                 }
5730                                                 if(tutorialstage==20){
5731                                                         tutorialmaxtime=500;
5732                                                 }
5733                                                 if(tutorialstage==21){
5734                                                         tutorialmaxtime=500;
5735                                                         if(bonus==cannon){
5736                                                                 bonus=Slicebonus;
5737                                                                 againbonus=1;
5738                                                         }
5739                                                         else againbonus=0;
5740                                                 }
5741                                                 if(tutorialstage==22){
5742                                                         tutorialmaxtime=500;
5743                                                 }
5744                                                 if(tutorialstage==23){
5745                                                         tutorialmaxtime=500;
5746                                                 }
5747                                                 if(tutorialstage==24){
5748                                                         tutorialmaxtime=500;
5749                                                 }
5750                                                 if(tutorialstage==25){
5751                                                         tutorialmaxtime=500;
5752                                                 }
5753                                                 if(tutorialstage==26){
5754                                                         tutorialmaxtime=2;
5755                                                 }
5756                                                 if(tutorialstage==27){
5757                                                         tutorialmaxtime=4;
5758                                                         reversaltrain=1;
5759                                                         cananger=1;
5760                                                         player[1].aitype=attacktypecutoff;
5761                                                 }
5762                                                 if(tutorialstage==28){
5763                                                         tutorialmaxtime=400;
5764                                                 }
5765                                                 if(tutorialstage==29){
5766                                                         tutorialmaxtime=400;
5767                                                         player[0].escapednum=0;
5768                                                 }
5769                                                 if(tutorialstage==30){
5770                                                         tutorialmaxtime=4;
5771                                                         reversaltrain=0;
5772                                                         cananger=0;
5773                                                         player[1].aitype=passivetype;
5774                                                 }
5775                                                 if(tutorialstage==31){
5776                                                         tutorialmaxtime=13;
5777                                                 }
5778                                                 if(tutorialstage==32){
5779                                                         tutorialmaxtime=8;
5780                                                 }
5781                                                 if(tutorialstage==33){
5782                                                         tutorialmaxtime=400;
5783                                                         cananger=1;
5784                                                         canattack=1;
5785                                                         player[1].aitype=attacktypecutoff;
5786                                                 }
5787                                                 if(tutorialstage==34){
5788                                                         tutorialmaxtime=400;
5789                                                 }
5790                                                 if(tutorialstage==35){
5791                                                         tutorialmaxtime=400;
5792                                                 }
5793                                                 if(tutorialstage==36){
5794                                                         tutorialmaxtime=2;
5795                                                         reversaltrain=0;
5796                                                         cananger=0;
5797                                                         player[1].aitype=passivetype;
5798                                                 }
5799                                                 if(tutorialstage==37){
5800                                                         damagedealt=0;
5801                                                         damagetaken=0;
5802                                                         tutorialmaxtime=50;
5803                                                         cananger=1;
5804                                                         canattack=1;
5805                                                         player[1].aitype=attacktypecutoff;
5806                                                 }
5807                                                 if(tutorialstage==38){
5808                                                         tutorialmaxtime=4;
5809                                                         canattack=0;
5810                                                         cananger=0;
5811                                                         player[1].aitype=passivetype;
5812                                                 }
5813                                                 if(tutorialstage==39){
5814                                                         XYZ temp,temp2;
5815
5816                                                         temp.x=1011;
5817                                                         temp.y=84;
5818                                                         temp.z=491;
5819                                                         temp2.x=1025;
5820                                                         temp2.y=75;
5821                                                         temp2.z=447;
5822
5823
5824                                                         weapons.owner[weapons.numweapons]=-1;
5825                                                         weapons.type[weapons.numweapons]=knife;
5826                                                         weapons.damage[weapons.numweapons]=0;
5827                                                         weapons.mass[weapons.numweapons]=1;
5828                                                         weapons.tipmass[weapons.numweapons]=1.2;
5829                                                         weapons.length[weapons.numweapons]=.25;
5830                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
5831                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
5832
5833                                                         weapons.velocity[weapons.numweapons]=0.1;
5834                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
5835                                                         weapons.missed[weapons.numweapons]=1;
5836                                                         weapons.hitsomething[weapons.numweapons]=0;
5837                                                         weapons.freetime[weapons.numweapons]=0;
5838                                                         weapons.firstfree[weapons.numweapons]=1;
5839                                                         weapons.physics[weapons.numweapons]=1;
5840
5841                                                         weapons.numweapons++;
5842                                                 }
5843                                                 if(tutorialstage==40){
5844                                                         tutorialmaxtime=300;
5845                                                 }
5846                                                 if(tutorialstage==41){
5847                                                         tutorialmaxtime=300;
5848                                                 }
5849                                                 if(tutorialstage==42){
5850                                                         tutorialmaxtime=8;
5851                                                 }
5852                                                 if(tutorialstage==43){
5853                                                         tutorialmaxtime=300;
5854                                                 }
5855                                                 if(tutorialstage==44){
5856                                                         weapons.owner[0]=1;
5857                                                         player[0].weaponactive=-1;
5858                                                         player[0].num_weapons=0;
5859                                                         player[1].weaponactive=0;
5860                                                         player[1].num_weapons=1;
5861                                                         player[1].weaponids[0]=0;
5862
5863                                                         cananger=1;
5864                                                         canattack=1;
5865                                                         player[1].aitype=attacktypecutoff;
5866
5867                                                         tutorialmaxtime=300;
5868                                                 }
5869                                                 if(tutorialstage==45){
5870                                                         weapons.owner[0]=1;
5871                                                         player[0].weaponactive=-1;
5872                                                         player[0].num_weapons=0;
5873                                                         player[1].weaponactive=0;
5874                                                         player[1].num_weapons=1;
5875                                                         player[1].weaponids[0]=0;
5876
5877                                                         tutorialmaxtime=300;
5878                                                 }
5879                                                 if(tutorialstage==46){
5880                                                         weapons.owner[0]=1;
5881                                                         player[0].weaponactive=-1;
5882                                                         player[0].num_weapons=0;
5883                                                         player[1].weaponactive=0;
5884                                                         player[1].num_weapons=1;
5885                                                         player[1].weaponids[0]=0;
5886
5887                                                         weapons.type[0]=sword;
5888
5889                                                         tutorialmaxtime=300;
5890                                                 }
5891
5892                                                 if(tutorialstage==47){
5893                                                         tutorialmaxtime=10;
5894
5895                                                         XYZ temp,temp2;
5896
5897                                                         temp.x=1011;
5898                                                         temp.y=84;
5899                                                         temp.z=491;
5900                                                         temp2.x=1025;
5901                                                         temp2.y=75;
5902                                                         temp2.z=447;
5903
5904                                                         weapons.owner[weapons.numweapons]=-1;
5905                                                         weapons.type[weapons.numweapons]=sword;
5906                                                         weapons.damage[weapons.numweapons]=0;
5907                                                         weapons.mass[weapons.numweapons]=1;
5908                                                         weapons.tipmass[weapons.numweapons]=1.2;
5909                                                         weapons.length[weapons.numweapons]=.25;
5910                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
5911                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
5912
5913                                                         weapons.velocity[weapons.numweapons]=0.1;
5914                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
5915                                                         weapons.missed[weapons.numweapons]=1;
5916                                                         weapons.hitsomething[weapons.numweapons]=0;
5917                                                         weapons.freetime[weapons.numweapons]=0;
5918                                                         weapons.firstfree[weapons.numweapons]=1;
5919                                                         weapons.physics[weapons.numweapons]=1;
5920
5921                                                         weapons.owner[0]=1;
5922                                                         weapons.owner[1]=0;
5923                                                         player[0].weaponactive=0;
5924                                                         player[0].num_weapons=1;
5925                                                         player[0].weaponids[0]=1;
5926                                                         player[1].weaponactive=0;
5927                                                         player[1].num_weapons=1;
5928                                                         player[1].weaponids[0]=0;
5929
5930                                                         weapons.numweapons++;
5931                                                 }
5932                                                 if(tutorialstage==48){
5933                                                         canattack=0;
5934                                                         cananger=0;
5935                                                         player[1].aitype=passivetype;
5936
5937                                                         tutorialmaxtime=15;
5938
5939                                                         weapons.owner[0]=1;
5940                                                         weapons.owner[1]=0;
5941                                                         player[0].weaponactive=0;
5942                                                         player[0].num_weapons=1;
5943                                                         player[0].weaponids[0]=1;
5944                                                         player[1].weaponactive=0;
5945                                                         player[1].num_weapons=1;
5946                                                         player[1].weaponids[0]=0;
5947
5948                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
5949                                                         else weapons.type[0]=staff;
5950
5951                                                         weapons.numweapons++;
5952                                                 }
5953                                                 if(tutorialstage==49){
5954                                                         canattack=0;
5955                                                         cananger=0;
5956                                                         player[1].aitype=passivetype;
5957
5958                                                         tutorialmaxtime=200;
5959
5960                                                         weapons.position[1]=1000;
5961                                                         weapons.tippoint[1]=1000;
5962
5963                                                         weapons.numweapons=1;
5964                                                         weapons.owner[0]=0;
5965                                                         player[1].weaponactive=-1;
5966                                                         player[1].num_weapons=0;
5967                                                         player[0].weaponactive=0;
5968                                                         player[0].num_weapons=1;
5969                                                         player[0].weaponids[0]=0;
5970
5971                                                         weapons.type[0]=knife;
5972
5973                                                         weapons.numweapons++;
5974                                                 }
5975                                                 if(tutorialstage==50){
5976                                                         tutorialmaxtime=8;
5977
5978                                                         XYZ temp,temp2;
5979                                                         float gLoc[3];
5980                                                         float vel[3];
5981                                                         gLoc[0]=player[1].coords.x;
5982                                                         gLoc[1]=player[1].coords.y;
5983                                                         gLoc[2]=player[1].coords.z;
5984                                                         vel[0]=0;
5985                                                         vel[1]=0;
5986                                                         vel[2]=0;
5987                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5988                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5989                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5990                                                         OPENAL_SetPaused(channels[fireendsound], false);
5991
5992                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5993                                                                 if(Random()%2==0){
5994                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5995                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5996                                                                         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;
5997                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5998                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5999                                                                 }
6000                                                         }
6001
6002                                                         player[1].num_weapons=0;
6003                                                         player[1].weaponstuck=-1;
6004                                                         player[1].weaponactive=-1;
6005
6006                                                         weapons.numweapons=0;
6007
6008                                                         weapons.owner[0]=-1;
6009                                                         weapons.velocity[0]=0.1;
6010                                                         weapons.tipvelocity[0]=-0.1;
6011                                                         weapons.missed[0]=1;
6012                                                         weapons.hitsomething[0]=0;
6013                                                         weapons.freetime[0]=0;
6014                                                         weapons.firstfree[0]=1;
6015                                                         weapons.physics[0]=1;
6016                                                 }
6017                                                 if(tutorialstage==51){
6018                                                         tutorialmaxtime=80000;
6019                                                 }
6020                                                 if(tutorialstage<=51)tutorialstagetime=0;
6021                                         }
6022
6023                                         //Tutorial success
6024                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6025                                                 if(tutorialstage==3){
6026                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6027                                                 }
6028                                                 if(tutorialstage==4){
6029                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6030                                                 }
6031                                                 if(tutorialstage==5){
6032                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6033                                                 }
6034                                                 if(tutorialstage==6){
6035                                                         if(player[0].isCrouch())tutorialsuccess=1;
6036                                                 }
6037                                                 if(tutorialstage==7){
6038                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6039                                                 }
6040                                                 if(tutorialstage==8){
6041                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6042                                                 }
6043                                                 if(tutorialstage==9){
6044                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6045                                                 }
6046                                                 if(tutorialstage==11){
6047                                                         if(player[0].isWallJump())tutorialsuccess=1;
6048                                                 }
6049                                                 if(tutorialstage==12){
6050                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6051                                                 }
6052                                                 if(tutorialstage==15){
6053                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6054                                                 }
6055                                                 if(tutorialstage==16){
6056                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6057                                                 }
6058                                                 if(tutorialstage==17){
6059                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6060                                                 }
6061                                                 if(tutorialstage==18){
6062                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6063                                                 }
6064                                                 if(tutorialstage==19){
6065                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6066                                                 }
6067                                                 if(tutorialstage==20){
6068                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6069                                                 }
6070                                                 if(tutorialstage==21){
6071                                                         if(bonus==cannon)tutorialsuccess=1;
6072                                                 }
6073                                                 if(tutorialstage==22){
6074                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6075                                                 }
6076                                                 if(tutorialstage==23){
6077                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6078                                                 }
6079                                                 if(tutorialstage==24){
6080                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6081                                                 }
6082                                                 if(tutorialstage==25){
6083                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6084                                                 }
6085                                                 if(tutorialstage==28){
6086                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6087                                                 }
6088                                                 if(tutorialstage==29){
6089                                                         if(player[0].escapednum==2){
6090                                                                 tutorialsuccess=1;
6091                                                                 reversaltrain=0;
6092                                                                 cananger=0;
6093                                                                 player[1].aitype=passivetype;
6094                                                         }
6095                                                 }
6096                                                 if(tutorialstage==33){
6097                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6098                                                 }
6099                                                 if(tutorialstage==34){
6100                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6101                                                 }
6102                                                 if(tutorialstage==35){
6103                                                         if(animation[player[0].targetanimation].attack==reversal){
6104                                                                 tutorialsuccess=1;
6105                                                                 reversaltrain=0;
6106                                                                 cananger=0;
6107                                                                 player[1].aitype=passivetype;
6108                                                         }
6109                                                 }
6110                                                 if(tutorialstage==40){
6111                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6112                                                 }
6113                                                 if(tutorialstage==41){
6114                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6115                                                 }
6116                                                 if(tutorialstage==43){
6117                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6118                                                 }
6119                                                 if(tutorialstage==44){
6120                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6121                                                 }
6122                                                 if(tutorialstage==45){
6123                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6124                                                 }
6125                                                 if(tutorialstage==46){
6126                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6127                                                 }
6128                                                 if(tutorialstage==49){
6129                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6130                                                 }
6131                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6132
6133
6134                                                 if(tutorialstagetime==tutorialmaxtime-3){
6135                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6136                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6137                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6138                                                 }
6139
6140                                                 if(tutorialsuccess>=1){
6141                                                         if(tutorialstage==34||tutorialstage==35)
6142                                                                 tutorialstagetime=tutorialmaxtime-1;
6143                                                 }
6144                                         }
6145
6146                                         if(tutoriallevel){
6147                                                 if(tutorialstage<14||tutorialstage>=50){
6148                                                         player[1].coords.y=300;
6149                                                         player[1].velocity=0;
6150                                                 }
6151                                         }
6152
6153                                         if(tutoriallevel!=1){
6154                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6155                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6156                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6157                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6158                                                 }
6159                                         }
6160                                         else
6161                                                 if(bonustime==0){
6162                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6163                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6164                                                         OPENAL_SetPaused(channels[fireendsound], false);
6165                                                 }
6166                                                 if(bonustime==0){
6167                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6168                                                         else bonusnum[bonus]+=0.15;
6169                                                         if(tutoriallevel)bonusvalue=0;
6170                                                         bonusvalue/=bonusnum[bonus];
6171                                                         bonustotal+=bonusvalue;
6172                                                 }
6173                                                 bonustime+=multiplier;
6174
6175                                                 if(environment==snowyenvironment){
6176                                                         precipdelay-=multiplier;
6177                                                         while(precipdelay<0){
6178                                                                 precipdelay+=.04;
6179                                                                 if(!detail)precipdelay+=.04;
6180                                                                 XYZ footvel,footpoint;
6181
6182                                                                 footvel=0;
6183                                                                 footpoint=viewer+viewerfacing*6;
6184                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6185                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6186                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6187                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6188                                                         }
6189                                                 }
6190                                                 for(k=0;k<numplayers;k++){
6191                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6192                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6193
6194                                                         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){
6195                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6196                                                                 else if(player[k].rotation>player[k].targetrotation){
6197                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6198                                                                 }
6199                                                                 else if(player[k].rotation<player[k].targetrotation){
6200                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6201                                                                 }
6202                                                         }
6203
6204
6205                                                         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))){
6206                                                                 player[k].turnspeed*=2;
6207                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6208                                                                 else if(player[k].rotation>player[k].targetrotation){
6209                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6210                                                                 }
6211                                                                 else if(player[k].rotation<player[k].targetrotation){
6212                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6213                                                                 }
6214                                                                 player[k].turnspeed/=2;
6215                                                         }
6216
6217                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6218                                                                 player[k].turnspeed*=4;
6219                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6220                                                                 else if(player[k].rotation>player[k].targetrotation){
6221                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6222                                                                 }
6223                                                                 else if(player[k].rotation<player[k].targetrotation){
6224                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6225                                                                 }
6226                                                                 player[k].turnspeed/=4;
6227                                                         }
6228
6229                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6230                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6231
6232                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6233                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6234                                                                         bool tempcollide=0;
6235
6236                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6237                                                                         if(player[k].collide>1)player[k].collide=1;
6238                                                                         player[k].collide-=multiplier*30;
6239
6240                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6241                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6242                                                                         }
6243                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6244                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6245                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6246                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6247                                                                                                 lowpoint=player[k].coords;
6248                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6249                                                                                                 else lowpoint.y+=1.3;
6250                                                                                                 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){
6251                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6252                                                                                                 }
6253                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6254                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6255                                                                                                 */
6256                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6257                                                                                                         flatfacing=lowpoint-player[k].coords;
6258                                                                                                         player[k].coords=lowpoint;
6259                                                                                                         player[k].coords.y-=1.3;
6260                                                                                                         player[k].collide=1;
6261                                                                                                         tempcollide=1;
6262                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6263                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6264                                                                                                                 tempcoords1=lowpoint;
6265                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6266                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6267                                                                                                                         player[k].target=0;
6268                                                                                                                         player[k].targetanimation=walljumpleftanim;
6269                                                                                                                         player[k].targetframe=0;
6270                                                                                                                         float gLoc[3];
6271                                                                                                                         float vel[3];
6272                                                                                                                         gLoc[0]=player[k].coords.x;
6273                                                                                                                         gLoc[1]=player[k].coords.y;
6274                                                                                                                         gLoc[2]=player[k].coords.z;
6275                                                                                                                         vel[0]=0;
6276                                                                                                                         vel[1]=0;
6277                                                                                                                         vel[2]=0;
6278                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6279                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6280                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6281                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6282                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6283
6284                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6285                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6286                                                                                                                         player[k].rotation*=360/6.28;
6287                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6288                                                                                                                         player[k].targetrotation=player[k].rotation;
6289                                                                                                                         player[k].lowrotation=player[k].rotation;
6290                                                                                                                         if(k==0)numwallflipped++;
6291                                                                                                                 }
6292                                                                                                                 else
6293                                                                                                                 {
6294                                                                                                                         lowpoint=tempcoords1;
6295                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6296                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6297                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6298                                                                                                                                 player[k].target=0;
6299                                                                                                                                 player[k].targetanimation=walljumprightanim;
6300                                                                                                                                 player[k].targetframe=0;
6301                                                                                                                                 float gLoc[3];
6302                                                                                                                                 float vel[3];
6303                                                                                                                                 gLoc[0]=player[k].coords.x;
6304                                                                                                                                 gLoc[1]=player[k].coords.y;
6305                                                                                                                                 gLoc[2]=player[k].coords.z;
6306                                                                                                                                 vel[0]=0;
6307                                                                                                                                 vel[1]=0;
6308                                                                                                                                 vel[2]=0;
6309                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6310                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6311                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6312                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6313                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6314
6315                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6316                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6317                                                                                                                                 player[k].rotation*=360/6.28;
6318                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6319                                                                                                                                 player[k].targetrotation=player[k].rotation;
6320                                                                                                                                 player[k].lowrotation=player[k].rotation;
6321                                                                                                                                 if(k==0)numwallflipped++;
6322                                                                                                                         }
6323                                                                                                                         else
6324                                                                                                                         {
6325                                                                                                                                 lowpoint=tempcoords1;
6326                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6327                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6328                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6329                                                                                                                                         player[k].target=0;
6330                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6331                                                                                                                                         player[k].targetframe=0;
6332                                                                                                                                         float gLoc[3];
6333                                                                                                                                         float vel[3];
6334                                                                                                                                         gLoc[0]=player[k].coords.x;
6335                                                                                                                                         gLoc[1]=player[k].coords.y;
6336                                                                                                                                         gLoc[2]=player[k].coords.z;
6337                                                                                                                                         vel[0]=0;
6338                                                                                                                                         vel[1]=0;
6339                                                                                                                                         vel[2]=0;
6340                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6341                                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6342                                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6343                                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6344                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6345
6346                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6347                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6348                                                                                                                                         player[k].rotation*=360/6.28;
6349                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6350                                                                                                                                         player[k].targetrotation=player[k].rotation;
6351                                                                                                                                         player[k].lowrotation=player[k].rotation;
6352                                                                                                                                         if(k==0)numwallflipped++;
6353                                                                                                                                 }
6354                                                                                                                                 else
6355                                                                                                                                 {
6356                                                                                                                                         lowpoint=tempcoords1;
6357                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6358                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6359                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6360                                                                                                                                                 player[k].target=0;
6361                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6362                                                                                                                                                 player[k].targetframe=0;
6363                                                                                                                                                 float gLoc[3];
6364                                                                                                                                                 float vel[3];
6365                                                                                                                                                 gLoc[0]=player[k].coords.x;
6366                                                                                                                                                 gLoc[1]=player[k].coords.y;
6367                                                                                                                                                 gLoc[2]=player[k].coords.z;
6368                                                                                                                                                 vel[0]=0;
6369                                                                                                                                                 vel[1]=0;
6370                                                                                                                                                 vel[2]=0;
6371                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6372                                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6373                                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6374                                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6375                                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6376
6377                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6378                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6379                                                                                                                                                 player[k].rotation*=360/6.28;
6380                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6381                                                                                                                                                 player[k].rotation+=180;
6382                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6383                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6384                                                                                                                                                 if(k==0)numwallflipped++;
6385                                                                                                                                         }
6386                                                                                                                                 }
6387                                                                                                                         }
6388                                                                                                                 }
6389                                                                                                         }
6390                                                                                                 }
6391                                                                                         }
6392                                                                                         else if(objects.type[i]==rocktype){
6393                                                                                                 lowpoint2=player[k].coords;
6394                                                                                                 lowpoint=player[k].coords;
6395                                                                                                 lowpoint.y+=2;
6396                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6397                                                                                                         player[k].coords=colpoint;
6398                                                                                                         player[k].collide=1;
6399                                                                                                         tempcollide=1;
6400
6401                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6402                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6403
6404                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6405                                                                                                                 player[k].target=0;
6406                                                                                                                 player[k].targetframe=0;
6407                                                                                                                 player[k].onterrain=1;
6408
6409                                                                                                                 if(player[k].id==0){
6410                                                                                                                         OPENAL_SetPaused(channels[whooshsound], true);
6411                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
6412                                                                                                                 }
6413
6414                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6415                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6416                                                                                                                         player[k].targetanimation=player[k].getLanding();
6417                                                                                                                         float gLoc[3];
6418                                                                                                                         float vel[3];
6419                                                                                                                         gLoc[0]=player[k].coords.x;
6420                                                                                                                         gLoc[1]=player[k].coords.y;
6421                                                                                                                         gLoc[2]=player[k].coords.z;
6422                                                                                                                         vel[0]=player[k].velocity.x;
6423                                                                                                                         vel[1]=player[k].velocity.y;
6424                                                                                                                         vel[2]=player[k].velocity.z;
6425                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6426                                                                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
6427                                                                                                                         OPENAL_SetVolume(channels[landsound], 128);
6428                                                                                                                         OPENAL_SetPaused(channels[landsound], false);
6429                                                                                                                         if(k==0){
6430                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6431                                                                                                                                 envsoundvol[numenvsounds]=16;
6432                                                                                                                                 envsoundlife[numenvsounds]=.4;
6433                                                                                                                                 numenvsounds++;
6434                                                                                                                         }
6435
6436                                                                                                                 }
6437                                                                                                         }
6438                                                                                                 }
6439                                                                                         }
6440                                                                                 }
6441                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6442                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6443                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6444                                                                                                 lowpoint=player[k].coords;
6445                                                                                                 lowpoint.y+=1.35;
6446                                                                                                 if(objects.type[i]!=rocktype)
6447                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6448                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
6449                                                                                                                 player[k].coords=lowpoint;
6450                                                                                                                 player[k].coords.y-=1.35;
6451                                                                                                                 player[k].collide=1;
6452
6453                                                                                                                 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)){
6454                                                                                                                         lowpoint=player[k].coords;
6455                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6456                                                                                                                         lowpoint=player[k].coords;
6457                                                                                                                         lowpoint.y+=.05;
6458                                                                                                                         facing=0;
6459                                                                                                                         facing.z=-1;
6460                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6461                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6462                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6463                                                                                                                         if(whichhit!=-1){
6464                                                                                                                                 lowpoint=player[k].coords;
6465                                                                                                                                 lowpoint.y+=.1;
6466                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6467                                                                                                                                 lowpoint2=lowpoint;
6468                                                                                                                                 lowpointtarget2=lowpointtarget;
6469                                                                                                                                 lowpoint3=lowpoint;
6470                                                                                                                                 lowpointtarget3=lowpointtarget;
6471                                                                                                                                 lowpoint4=lowpoint;
6472                                                                                                                                 lowpointtarget4=lowpointtarget;
6473                                                                                                                                 lowpoint5=lowpoint;
6474                                                                                                                                 lowpointtarget5=lowpointtarget;
6475                                                                                                                                 lowpoint6=lowpoint;
6476                                                                                                                                 lowpointtarget6=lowpointtarget;
6477                                                                                                                                 lowpoint7=lowpoint;
6478                                                                                                                                 lowpointtarget7=lowpoint;
6479                                                                                                                                 lowpoint2.x+=.1;
6480                                                                                                                                 lowpointtarget2.x+=.1;
6481                                                                                                                                 lowpoint3.z+=.1;
6482                                                                                                                                 lowpointtarget3.z+=.1;
6483                                                                                                                                 lowpoint4.x-=.1;
6484                                                                                                                                 lowpointtarget4.x-=.1;
6485                                                                                                                                 lowpoint5.z-=.1;
6486                                                                                                                                 lowpointtarget5.z-=.1;
6487                                                                                                                                 lowpoint6.y+=45/13;
6488                                                                                                                                 lowpointtarget6.y+=45/13;
6489                                                                                                                                 lowpointtarget6+=facing*.6;
6490                                                                                                                                 lowpointtarget7.y+=90/13;
6491                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6492                                                                                                                                 if(objects.friction[i]>.5)
6493                                                                                                                                         if(whichhit!=-1){
6494                                                                                                                                                 //if(k==0){
6495                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6496                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6497                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6498                                                                                                                                                                 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)
6499                                                                                                                                                                         for(j=0;j<45;j++){
6500                                                                                                                                                                                 lowpoint=player[k].coords;
6501                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6502                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6503                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6504                                                                                                                                                                                         if(j<=6){
6505                                                                                                                                                                                                 j=100;
6506                                                                                                                                                                                         }
6507                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6508                                                                                                                                                                                         j=100;
6509                                                                                                                                                                                         }*/
6510                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6511                                                                                                                                                                                                 j=100;
6512                                                                                                                                                                                         }
6513                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6514                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6515                                                                                                                                                                                                 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)*/){
6516                                                                                                                                                                                                         lowpoint=player[k].coords;
6517                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6518                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6519                                                                                                                                                                                                         flatfacing=player[k].coords;
6520                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6521                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6522                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6523
6524                                                                                                                                                                                                         if(j>10||!player[k].isRun()){
6525                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6526                                                                                                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6527                                                                                                                                                                                                                 }
6528                                                                                                                                                                                                                 float gLoc[3];
6529                                                                                                                                                                                                                 float vel[3];
6530                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6531                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6532                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6533                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6534                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6535                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6536                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
6537                                                                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6538                                                                                                                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
6539                                                                                                                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
6540
6541                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6542                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6543                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6544                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6545                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6546                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6547
6548                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6549                                                                                                                                                                                                                 player[k].velocity=0;
6550
6551                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6552                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6553                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6554                                                                                                                                                                                                                         player[k].jumppower=0;
6555                                                                                                                                                                                                                         player[k].jumpclimb=1;
6556                                                                                                                                                                                                                 }
6557                                                                                                                                                                                                                 player[k].transspeed=6;
6558                                                                                                                                                                                                                 player[k].target=0;
6559
6560                                                                                                                                                                                                                 //player[k].currentframe=1;
6561                                                                                                                                                                                                                 player[k].targetframe=1;
6562                                                                                                                                                                                                                 if(j>25){
6563                                                                                                                                                                                                                         //player[k].currentframe=0;
6564                                                                                                                                                                                                                         player[k].targetframe=0;
6565                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6566                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6567                                                                                                                                                                                                                         player[k].jumppower=0;
6568                                                                                                                                                                                                                 }
6569                                                                                                                                                                                                         }
6570                                                                                                                                                                                                         j=100;
6571                                                                                                                                                                                                 }
6572                                                                                                                                                                                         }
6573                                                                                                                                                                                 }
6574                                                                                                                                                                         }
6575                                                                                                                                                                         //}
6576                                                                                                                                         }
6577                                                                                                                         }
6578                                                                                                                 }
6579                                                                                                         }
6580                                                                                         }
6581                                                                                         if(player[k].collide<=0){
6582                                                                                                 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()){
6583                                                                                                         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)){
6584                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6585                                                                                                                 player[k].targetanimation=jumpdownanim;
6586                                                                                                                 player[k].targetframe=0;
6587                                                                                                                 player[k].target=0;
6588
6589                                                                                                                 float gLoc[3];
6590                                                                                                                 float vel[3];
6591                                                                                                                 gLoc[0]=player[k].coords.x;
6592                                                                                                                 gLoc[1]=player[k].coords.y;
6593                                                                                                                 gLoc[2]=player[k].coords.z;
6594                                                                                                                 vel[0]=player[k].velocity.x;
6595                                                                                                                 vel[1]=player[k].velocity.y;
6596                                                                                                                 vel[2]=player[k].velocity.z;
6597                                                                                                                 if(k==0){
6598                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
6599                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6600                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
6601                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
6602                                                                                                                 }
6603                                                                                                         }
6604                                                                                                         player[k].velocity.y+=gravity;
6605                                                                                                 }
6606                                                                                         }
6607                                                                 }
6608                                                         }
6609                                                         player[k].realoldcoords=player[k].coords;
6610                                                 }
6611
6612                                                 static XYZ oldviewer;
6613
6614                                                 if(indialogue==-1){
6615                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6616                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6617                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6618                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6619                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6620                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6621                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6622                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6623                                                 }
6624                                                 else
6625                                                 {
6626                                                         player[0].forwardkeydown=0;
6627                                                         player[0].leftkeydown=0;
6628                                                         player[0].backkeydown=0;
6629                                                         player[0].rightkeydown=0;
6630                                                         player[0].jumpkeydown=0;
6631                                                         player[0].crouchkeydown=0;
6632                                                         player[0].drawkeydown=0;
6633                                                         player[0].throwkeydown=0;
6634                                                 }
6635
6636                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6637
6638
6639                                                 static bool endkeydown;
6640                                                 if(indialogue!=-1){
6641                                                         cameramode=1;
6642                                                         if(directing){
6643                                                                 facing=0;
6644                                                                 facing.z=-1;
6645
6646                                                                 facing=DoRotation(facing,-rotation2,0,0);
6647                                                                 facing=DoRotation(facing,0,0-rotation,0);
6648
6649                                                                 flatfacing=0;
6650                                                                 flatfacing.z=-1;
6651
6652                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6653
6654                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6655                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6656                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6657                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6658                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6659                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6660                                                                 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)
6661                                                                         ||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)
6662                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6663                                                                                 int whichend;
6664                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6665                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6666                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6667                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6668                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6669                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6670                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6671                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6672                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6673                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6674                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6675                                                                                 if(whichend!=-1){
6676                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6677                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6678                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6679                                                                                 }
6680                                                                                 if(whichend==-1){
6681                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6682                                                                                 }
6683                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6684                                                                                         indialogue=-1;
6685                                                                                         directing=0;
6686                                                                                         cameramode=0;
6687                                                                                 }
6688                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6689                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6690                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6691                                                                                 indialogue++;
6692                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6693                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6694                                                                                                 static float gLoc[3];
6695                                                                                                 static float vel[3];
6696                                                                                                 XYZ temppos;
6697                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6698                                                                                                 temppos=temppos-viewer;
6699                                                                                                 Normalise(&temppos);
6700                                                                                                 temppos+=viewer;
6701
6702                                                                                                 gLoc[0]=temppos.x;
6703                                                                                                 gLoc[1]=temppos.y;
6704                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
6705                                                                                                 vel[1]=0;
6706                                                                                                 vel[2]=0;
6707                                                                                                 int whichsoundplay;
6708                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6709                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6710                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6711                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6712                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6713                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6714                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6715                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6716                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6717                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6718                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6719                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6720                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6721                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6722                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6723                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6724                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6725                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6726                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6727                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6728                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6729                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6730                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6731                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6732                                                                                         }
6733                                                                                 }
6734
6735                                                                                 for(j=0;j<numplayers;j++){
6736                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6737                                                                                 }
6738
6739                                                                                 endkeydown=1;
6740                                                                         }
6741                                                                         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)
6742                                                                                 ||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)
6743                                                                                 )){
6744                                                                                         int whichend;
6745                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
6746                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
6747                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
6748                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
6749                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
6750                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
6751                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
6752                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
6753                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
6754                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
6755                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
6756                                                                                 }
6757                                                                                 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)
6758                                                                                         &&!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)
6759                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6760                                                                                                 endkeydown=0;
6761                                                                                         }
6762                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6763                                                                                                 indialogue=-1;
6764                                                                                                 directing=0;
6765                                                                                                 cameramode=0;
6766                                                                                         }
6767                                                         }
6768                                                         if(!directing){
6769                                                                 OPENAL_SetPaused(channels[whooshsound], true);
6770                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
6771                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
6772                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
6773                                                                 }
6774                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6775                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6776                                                                 if(dialoguetime>0.5)
6777                                                                         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)
6778                                                                                 ||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)
6779                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
6780                                                                                         indialogue++;
6781                                                                                         endkeydown=1;
6782                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
6783                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6784                                                                                                         static float gLoc[3];
6785                                                                                                         static float vel[3];
6786                                                                                                         XYZ temppos;
6787                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6788                                                                                                         temppos=temppos-viewer;
6789                                                                                                         Normalise(&temppos);
6790                                                                                                         temppos+=viewer;
6791
6792                                                                                                         gLoc[0]=temppos.x;
6793                                                                                                         gLoc[1]=temppos.y;
6794                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
6795                                                                                                         vel[1]=0;
6796                                                                                                         vel[2]=0;
6797                                                                                                         int whichsoundplay;
6798                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6799                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6800                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6801                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6802                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6803                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6804                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6805                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6806                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6807                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6808                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6809                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6810                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6811                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6812                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6813                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6814                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6815                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6816                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6817                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6818                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
6819                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
6820                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6821                                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6822                                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6823                                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6824                                                                                                         }
6825                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
6826                                                                                                                 hotspot[numhotspots]=player[0].coords;
6827                                                                                                                 hotspotsize[numhotspots]=10;
6828                                                                                                                 hotspottype[numhotspots]=-1;
6829
6830                                                                                                                 numhotspots++;
6831                                                                                                         }
6832                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
6833                                                                                                                 hostile=1;
6834                                                                                                         }
6835
6836                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
6837                                                                                                                 indialogue=-1;
6838                                                                                                                 directing=0;
6839                                                                                                                 cameramode=0;
6840                                                                                                         }
6841                                                                                                 }
6842                                                                                         }
6843                                                                                 }
6844                                                                                 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)
6845                                                                                         &&!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)
6846                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6847                                                                                                 endkeydown=0;
6848                                                                                         }
6849                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6850                                                                                                 indialogue=-1;
6851                                                                                                 directing=0;
6852                                                                                                 cameramode=0;
6853                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6854                                                                                                         hostile=1;
6855                                                                                                 }
6856                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6857                                                                                                         windialogue=1;
6858                                                                                                 }
6859                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6860                                                                                                         hostile=1;
6861                                                                                                         for(i=1;i<numplayers;i++){
6862                                                                                                                 player[i].aitype = attacktypecutoff;
6863                                                                                                         }
6864                                                                                                 }
6865                                                                                         }
6866                                                         }
6867                                                 }
6868
6869                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
6870                                                 else oldbuttondialogue=1;
6871
6872                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
6873
6874                                                 //Net updates
6875
6876                                                 /*keyrefreshdelay-=multiplier;
6877                                                 bigrefreshdelay-=multiplier;
6878
6879                                                 if(keyrefreshdelay<=0){
6880                                                 static int concat[4];
6881
6882                                                 concat[0]=player[0].forwardkeydown;
6883                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
6884                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
6885                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
6886                                                 concat[0]=concat[0]*2+player[0].backkeydown;
6887                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
6888                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
6889                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
6890
6891                                                 concat[1]=player[0].crouchtogglekeydown;
6892                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
6893                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
6894                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
6895                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
6896                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
6897
6898                                                 //concat[2]=(char)((int)(rotation/2)%180);
6899
6900                                                 //concat[3]=(char)((int)(rotation2/2)%180);
6901
6902                                                 chatname[0]=concat[0]-128;
6903                                                 chatname[1]=concat[1]-128;
6904                                                 //chatname[2]=concat[2]-128;
6905                                                 //chatname[3]=concat[3]-128;
6906                                                 int temppoint=2;
6907                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
6908                                                 temppoint+=sizeof(float);
6909                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
6910                                                 temppoint+=sizeof(float);
6911
6912                                                 chatname[temppoint]='\0';
6913
6914                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
6915                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
6916                                                 //keyrefreshdelay=.01;
6917                                                 keyrefreshdelay=.03;
6918                                                 }
6919
6920                                                 if(bigrefreshdelay<=0){
6921                                                 for(i=0;i<1;i++){
6922                                                 /*int temppoint=0;
6923                                                 memcpy(chatname+temppoint,&i,sizeof(int));
6924                                                 temppoint+=sizeof(int);
6925                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
6926                                                 temppoint+=sizeof(float);
6927                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
6928                                                 temppoint+=sizeof(float);
6929                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
6930                                                 temppoint+=sizeof(float);
6931                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
6932                                                 temppoint+=sizeof(float);
6933                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
6934                                                 temppoint+=sizeof(float);
6935                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
6936                                                 temppoint+=sizeof(int);
6937                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
6938                                                 temppoint+=sizeof(int);
6939                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
6940                                                 temppoint+=sizeof(float);
6941                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
6942                                                 temppoint+=sizeof(float);
6943                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
6944                                                 temppoint+=sizeof(float);
6945                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
6946                                                 temppoint+=sizeof(int);
6947                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
6948                                                 temppoint+=sizeof(int);
6949                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
6950                                                 temppoint+=sizeof(float);
6951                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
6952                                                 temppoint+=sizeof(float);
6953                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
6954                                                 temppoint+=sizeof(float);
6955                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
6956                                                 temppoint+=sizeof(int);
6957                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
6958                                                 temppoint+=sizeof(int);
6959                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
6960                                                 temppoint+=sizeof(int);
6961                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
6962                                                 temppoint+=sizeof(int);
6963                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
6964                                                 temppoint+=sizeof(int);
6965                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
6966                                                 temppoint+=sizeof(int);
6967                                                 chatname[temppoint]='\0';
6968
6969                                                 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);
6970                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
6971                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
6972
6973                                                 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);
6974
6975                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
6976                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
6977                                                 }
6978                                                 //bigrefreshdelay=.02;
6979                                                 bigrefreshdelay=.1;
6980                                                 }
6981                                                 }*/
6982
6983                                                 if(!player[0].jumpkeydown){
6984                                                         player[0].jumptogglekeydown=0;
6985                                                 }
6986                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
6987
6988
6989                                                 dialoguetime+=multiplier;
6990                                                 skybox.cloudmove+=multiplier;
6991                                                 hawkrotation+=multiplier*25;
6992                                                 realhawkcoords=0;
6993                                                 realhawkcoords.x=25;
6994                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6995                                                 hawkcalldelay-=multiplier/2;
6996
6997                                                 if(hawkcalldelay<=0)
6998                                                 {
6999                                                         static float gLoc[3];
7000                                                         static float vel[3];
7001                                                         gLoc[0]=realhawkcoords.x;
7002                                                         gLoc[1]=realhawkcoords.y;
7003                                                         gLoc[2]=realhawkcoords.z;
7004                                                         vel[0]=0;
7005                                                         vel[1]=0;
7006                                                         vel[2]=0;
7007                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, true);
7008                                                         OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
7009                                                         OPENAL_SetVolume(channels[hawksound], 128);
7010                                                         OPENAL_SetPaused(channels[hawksound], false);
7011
7012                                                         hawkcalldelay=16+abs(Random()%8);
7013                                                 }
7014                                                 static float temptexdetail;
7015
7016
7017                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7018                                                         player[0].damagetolerance=200000;
7019                                                         player[0].damage=0;
7020                                                         player[0].burnt=0;
7021                                                         player[0].permanentdamage=0;
7022                                                         player[0].superpermanentdamage=0;
7023                                                         /*
7024                                                         int whichchar;
7025                                                         whichchar = abs(Random()%7);
7026                                                         registrationname[whichchar]+=1;
7027                                                         */
7028                                                 }
7029
7030                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7031                                                         environment++;
7032                                                         if(environment>2)environment=0;
7033                                                         Setenvironment(environment);
7034
7035                                                         envtogglekeydown=1;
7036                                                 }
7037
7038
7039                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7040                                                         envtogglekeydown=0;
7041                                                 }
7042
7043                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7044                                                         cameramode=1-cameramode;
7045                                                         cameratogglekeydown=1;
7046                                                 }
7047
7048                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7049                                                         cameratogglekeydown=0;
7050                                                 }
7051
7052                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7053                                                         if(player[0].num_weapons>0){
7054                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7055                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7056                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7057                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7058                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7059                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7060                                                                         weapons.length[player[0].weaponids[0]]=.8;
7061                                                                 }
7062                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7063                                                                         weapons.mass[player[0].weaponids[0]]=2;
7064                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7065                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7066                                                                 }
7067
7068                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7069                                                                         weapons.mass[player[0].weaponids[0]]=1;
7070                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7071                                                                         weapons.length[player[0].weaponids[0]]=.25;
7072                                                                 }
7073                                                         }
7074
7075                                                         /*for(i=0;i<objects.numobjects;i++){
7076                                                         if(objects.type[i]==treeleavestype){
7077                                                         for(j=0;j<objects.numobjects;j++){
7078                                                         if(objects.type[j]==treetrunktype)
7079                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7080                                                         objects.scale[i]=objects.scale[j];
7081                                                         }
7082                                                         }
7083                                                         }*/
7084                                                         detailtogglekeydown=1;
7085                                                 }
7086
7087                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7088                                                         int closest=-1;
7089                                                         float closestdist=-1;
7090                                                         float distance;
7091                                                         if(numplayers>1)
7092                                                                 for(i=1;i<numplayers;i++){
7093                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7094                                                                         if(closestdist==-1||distance<closestdist){
7095                                                                                 closestdist=distance;
7096                                                                                 closest=i;
7097                                                                         }
7098                                                                 }
7099                                                                 if(closest!=-1){
7100                                                                         if(player[closest].num_weapons)
7101                                                                         {
7102                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7103                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7104                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7105                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7106                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7107                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7108                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7109                                                                                 }
7110                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7111                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7112                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7113                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7114                                                                                 }
7115                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7116                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7117                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7118                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7119                                                                                 }
7120                                                                         }
7121                                                                         if(!player[closest].num_weapons)
7122                                                                         {
7123                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7124                                                                                 weapons.owner[weapons.numweapons]=closest;
7125                                                                                 weapons.type[weapons.numweapons]=knife;
7126                                                                                 weapons.damage[weapons.numweapons]=0;
7127                                                                                 weapons.numweapons++;
7128                                                                                 player[closest].num_weapons=1;
7129                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7130                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7131                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7132                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7133                                                                                 }
7134                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7135                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7136                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7137                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7138                                                                                 }
7139                                                                         }
7140                                                                 }
7141                                                                 detailtogglekeydown=1;
7142                                                 }
7143
7144                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7145                                                         int closest=-1;
7146                                                         float closestdist=-1;
7147                                                         float distance;
7148                                                         if(numplayers>1)
7149                                                                 for(i=1;i<numplayers;i++){
7150                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7151                                                                         if(closestdist==-1||distance<closestdist){
7152                                                                                 closestdist=distance;
7153                                                                                 closest=i;
7154                                                                         }
7155                                                                 }
7156
7157                                                                 player[closest].rotation+=multiplier*50;
7158                                                                 player[closest].targetrotation=player[closest].rotation;
7159                                                 }
7160
7161
7162                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7163                                                         int closest=-1;
7164                                                         float closestdist=-1;
7165                                                         float distance;
7166                                                         if(numplayers>1)
7167                                                                 for(i=1;i<numplayers;i++){
7168                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7169                                                                         if(closestdist==-1||distance<closestdist){
7170                                                                                 closestdist=distance;
7171                                                                                 closest=i;
7172                                                                         }
7173                                                                 }
7174                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7175
7176                                                                 if(closest!=-1){
7177                                                                         player[closest].whichskin++;
7178                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7179                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7180
7181                                                                         if(player[closest].creature==rabbittype){
7182                                                                                 if(player[closest].whichskin==0){
7183                                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7184                                                                                 }
7185                                                                                 else if(player[closest].whichskin==1){
7186                                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7187                                                                                 }
7188                                                                                 else if(player[closest].whichskin==2){
7189                                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7190                                                                                 }
7191                                                                                 else if(player[closest].whichskin==3){
7192                                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7193                                                                                 }
7194                                                                                 else if(player[closest].whichskin==4){
7195                                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7196                                                                                 }
7197                                                                                 else if(player[closest].whichskin==5){
7198                                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7199                                                                                 }
7200                                                                                 else if(player[closest].whichskin==6){
7201                                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7202                                                                                 }
7203                                                                                 else if(player[closest].whichskin==7){
7204                                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7205                                                                                 }
7206                                                                                 else if(player[closest].whichskin==8){
7207                                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7208                                                                                 }
7209                                                                                 else if(player[closest].whichskin==9){
7210                                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7211                                                                                 }
7212                                                                         }
7213                                                                         if(player[closest].creature==wolftype){
7214                                                                                 k=abs(Random()%3);
7215                                                                                 if(player[closest].whichskin==0){
7216                                                                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7217                                                                                 }
7218                                                                                 else if(player[closest].whichskin==1){
7219                                                                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7220                                                                                 }
7221                                                                                 else if(player[closest].whichskin==2){
7222                                                                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7223                                                                                 }
7224                                                                         }
7225                                                                 }
7226
7227                                                                 if(player[closest].numclothes){
7228                                                                         for(i=0;i<player[closest].numclothes;i++){
7229                                                                                 tintr=player[closest].clothestintr[i];
7230                                                                                 tintg=player[closest].clothestintg[i];
7231                                                                                 tintb=player[closest].clothestintb[i];
7232                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7233                                                                         }
7234                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7235                                                                 }
7236
7237                                                                 detailtogglekeydown=1;
7238                                                 }
7239
7240                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7241                                                         int closest=-1;
7242                                                         float closestdist=-1;
7243                                                         float distance;
7244                                                         if(numplayers>1)
7245                                                                 for(i=1;i<numplayers;i++){
7246                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7247                                                                         if(closestdist==-1||distance<closestdist){
7248                                                                                 closestdist=distance;
7249                                                                                 closest=i;
7250                                                                         }
7251                                                                 }
7252                                                                 if(closest!=-1){
7253                                                                         if(player[closest].creature==wolftype){
7254                                                                                 headprop=player[closest].proportionhead.x/1.1;
7255                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7256                                                                                 armprop=player[closest].proportionarms.x/1.1;
7257                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7258                                                                         }
7259
7260                                                                         if(player[closest].creature==rabbittype){
7261                                                                                 headprop=player[closest].proportionhead.x/1.2;
7262                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7263                                                                                 armprop=player[closest].proportionarms.x/1.00;
7264                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7265                                                                         }
7266
7267
7268                                                                         if(player[closest].creature==rabbittype){
7269                                                                                 player[closest].skeleton.id=closest;
7270                                                                                 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);
7271                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7272                                                                                 player[closest].whichskin=0;
7273                                                                                 player[closest].creature=wolftype;
7274
7275                                                                                 player[closest].proportionhead=1.1;
7276                                                                                 player[closest].proportionbody=1.1;
7277                                                                                 player[closest].proportionarms=1.1;
7278                                                                                 player[closest].proportionlegs=1.1;
7279                                                                                 player[closest].proportionlegs.y=1.1;
7280                                                                                 player[closest].scale=.23*5*player[0].scale;
7281
7282                                                                                 player[closest].damagetolerance=300;
7283                                                                         }
7284                                                                         else
7285                                                                         {
7286                                                                                 player[closest].skeleton.id=closest;
7287                                                                                 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);
7288                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7289                                                                                 player[closest].whichskin=0;
7290                                                                                 player[closest].creature=rabbittype;
7291
7292                                                                                 player[closest].proportionhead=1.2;
7293                                                                                 player[closest].proportionbody=1.05;
7294                                                                                 player[closest].proportionarms=1.00;
7295                                                                                 player[closest].proportionlegs=1.1;
7296                                                                                 player[closest].proportionlegs.y=1.05;
7297                                                                                 player[closest].scale=.2*5*player[0].scale;
7298
7299                                                                                 player[closest].damagetolerance=200;
7300                                                                         }
7301
7302                                                                         if(player[closest].creature==wolftype){
7303                                                                                 player[closest].proportionhead=1.1*headprop;
7304                                                                                 player[closest].proportionbody=1.1*bodyprop;
7305                                                                                 player[closest].proportionarms=1.1*armprop;
7306                                                                                 player[closest].proportionlegs=1.1*legprop;
7307                                                                         }
7308
7309                                                                         if(player[closest].creature==rabbittype){
7310                                                                                 player[closest].proportionhead=1.2*headprop;
7311                                                                                 player[closest].proportionbody=1.05*bodyprop;
7312                                                                                 player[closest].proportionarms=1.00*armprop;
7313                                                                                 player[closest].proportionlegs=1.1*legprop;
7314                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7315                                                                         }
7316
7317                                                                 }
7318                                                                 detailtogglekeydown=1;
7319                                                 }
7320
7321                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7322                                                         detailtogglekeydown=0;
7323                                                 }
7324
7325                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7326                                                         slomo=1-slomo;
7327                                                         slomodelay=1000;
7328                                                         slomotogglekeydown=1;
7329                                                 }
7330
7331
7332                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7333                                                         int closest=-1;
7334                                                         float closestdist=-1;
7335                                                         float distance;
7336                                                         XYZ flatfacing2,flatvelocity2;
7337                                                         XYZ blah;
7338                                                         if(numplayers>1)
7339                                                                 for(i=1;i<numplayers;i++){
7340                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7341                                                                         if(distance<144&&!player[i].headless)
7342                                                                                 if(closestdist==-1||distance<closestdist){
7343                                                                                         closestdist=distance;
7344                                                                                         closest=i;
7345                                                                                         blah = player[i].coords;
7346                                                                                 }
7347                                                                 }
7348
7349                                                                 if(closest!=-1){
7350                                                                         XYZ headspurtdirection;
7351                                                                         int i = player[closest].skeleton.jointlabels[head];
7352                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7353                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7354                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7355                                                                                 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;
7356                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7357                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7358                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7359                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7360                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7361                                                                                 Normalise(&headspurtdirection);
7362                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7363                                                                                 flatvelocity2+=headspurtdirection*8;
7364                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7365                                                                         }
7366                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7367
7368                                                                         float gLoc[3];
7369                                                                         float vel[3];
7370                                                                         gLoc[0]=blah.x;
7371                                                                         gLoc[1]=blah.y;
7372                                                                         gLoc[2]=blah.z;
7373                                                                         vel[0]=0;
7374                                                                         vel[1]=0;
7375                                                                         vel[2]=0;
7376                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7377                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7378                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7379                                                                         OPENAL_SetPaused(channels[splattersound], false);
7380
7381                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7382                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7383                                                                         OPENAL_SetVolume(channels[breaksound2], 100);
7384                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7385
7386                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7387                                                                         player[closest].RagDoll(0);
7388                                                                         player[closest].dead=2;
7389                                                                         player[closest].headless=1;
7390                                                                         player[closest].DoBloodBig(3,165);
7391
7392                                                                         camerashake+=.3;
7393                                                                 }
7394
7395                                                                 explodetogglekeydown=1;
7396                                                 }
7397
7398                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7399                                                         int closest=-1;
7400                                                         float closestdist=-1;
7401                                                         float distance;
7402                                                         XYZ flatfacing2,flatvelocity2;
7403                                                         XYZ blah;
7404                                                         if(numplayers>1)
7405                                                                 for(i=1;i<numplayers;i++){
7406                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7407                                                                         if(distance<144)
7408                                                                                 if(closestdist==-1||distance<closestdist){
7409                                                                                         closestdist=distance;
7410                                                                                         closest=i;
7411                                                                                         blah=player[i].coords;
7412                                                                                 }
7413                                                                 }
7414
7415                                                                 if(closest!=-1){
7416                                                                         float gLoc[3];
7417                                                                         float vel[3];
7418                                                                         gLoc[0]=blah.x;
7419                                                                         gLoc[1]=blah.y;
7420                                                                         gLoc[2]=blah.z;
7421                                                                         vel[0]=0;
7422                                                                         vel[1]=0;
7423                                                                         vel[2]=0;
7424
7425                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7426                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7427                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7428                                                                         OPENAL_SetPaused(channels[splattersound], false);
7429
7430                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7431                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7432                                                                         OPENAL_SetVolume(channels[breaksound2], 600);
7433                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7434
7435                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7436                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7437                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7438                                                                                 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;
7439                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7440                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7441                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7442                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7443                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7444                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7445                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7446                                                                         }
7447
7448                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7449                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7450                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7451                                                                                 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;
7452                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7453                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7454                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7455                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7456                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7457                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7458                                                                         }
7459
7460                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7461                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7462                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7463                                                                                 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;
7464                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7465                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7466                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7467                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7468                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7469                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7470                                                                         }
7471
7472                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7473                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7474                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7475                                                                                 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;
7476                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7477                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7478                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7479                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7480                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7481                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7482                                                                         }
7483
7484                                                                         XYZ temppos;
7485                                                                         for(j=0;j<numplayers; j++){
7486                                                                                 if(j!=closest){
7487                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7488                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7489                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7490                                                                                                 player[j].skeleton.longdead=0;
7491                                                                                                 player[j].RagDoll(0);
7492                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7493                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7494                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7495                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7496                                                                                                                 Normalise(&flatvelocity2);
7497                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7498                                                                                                         }
7499                                                                                                 }
7500                                                                                         }
7501                                                                                 }
7502                                                                         }
7503
7504                                                                         player[closest].DoDamage(10000);
7505                                                                         player[closest].RagDoll(0);
7506                                                                         player[closest].dead=2;
7507                                                                         player[closest].coords=20;
7508                                                                         player[closest].skeleton.free=2;
7509
7510                                                                         camerashake+=.6;
7511
7512                                                                 }
7513
7514                                                                 explodetogglekeydown=1;
7515                                                 }
7516
7517                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7518                                                         explodetogglekeydown=0;
7519                                                 }
7520
7521                                                 /*
7522                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7523                                                 FILE                    *tfile;
7524                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7525                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7526                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7527                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7528                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7529                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7530                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7531
7532                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7533                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7534                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7535                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7536                                                 for(j=0;j<player[0].num_weapons;j++){
7537                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7538                                                 }
7539                                                 fwrite( &environment, 1, sizeof(int), tfile );
7540
7541                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7542                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7543                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7544                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7545                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7546
7547                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7548                                                 if(numplayers>1&&numplayers<maxplayers)
7549                                                 for(i=1;i<numplayers;i++){
7550                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7551                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7552                                                 for(j=0;j<player[i].num_weapons;j++){
7553                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7554                                                 }
7555                                                 if(player[i].numwaypoints<30){
7556                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7557                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7558                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7559                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7560                                                 }
7561                                                 else{
7562                                                 player[i].numwaypoints=0;
7563                                                 player[i].waypoint=0;
7564                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7565                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7566                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7567                                                 }
7568                                                 }
7569
7570                                                 fclose(tfile);
7571
7572                                                 slomotogglekeydown=1;
7573                                                 }*/
7574
7575                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7576                                                         slomotogglekeydown=0;
7577                                                 }
7578
7579
7580                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7581                                                         player[0].onfire=1-player[0].onfire;
7582                                                         if(player[0].onfire){
7583                                                                 player[0].CatchFire();
7584                                                         }
7585                                                         if(!player[0].onfire){
7586                                                                 float gLoc[3];
7587                                                                 float vel[3];
7588                                                                 gLoc[0]=player[0].coords.x;
7589                                                                 gLoc[1]=player[0].coords.y;
7590                                                                 gLoc[2]=player[0].coords.z;
7591                                                                 vel[0]=0;
7592                                                                 vel[1]=0;
7593                                                                 vel[2]=0;
7594                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7595                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7596                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
7597                                                                 OPENAL_SetPaused(channels[fireendsound], false);
7598                                                                 OPENAL_SetPaused(channels[stream_firesound], true);
7599                                                         }
7600                                                         slomotogglekeydown=1;
7601                                                 }
7602                                                 /*
7603                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7604                                                 if(player[0].bleeding<=0)
7605                                                 player[0].DoBlood(1,255);
7606                                                 }*/
7607
7608
7609                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7610                                                         int closest=-1;
7611                                                         float closestdist=-1;
7612                                                         float distance;
7613                                                         if(numplayers>1)
7614                                                                 for(i=1;i<numplayers;i++){
7615                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7616                                                                         if(closestdist==-1||distance<closestdist){
7617                                                                                 closestdist=distance;
7618                                                                                 closest=i;
7619                                                                         }
7620                                                                 }
7621                                                                 if(closestdist>0&&closest>=0){
7622                                                                         //player[closest]=player[numplayers-1];
7623                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7624                                                                         numplayers--;
7625                                                                 }
7626                                                                 drawmodetogglekeydown=1;
7627                                                 }
7628
7629                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7630                                                         int closest=-1;
7631                                                         float closestdist=-1;
7632                                                         float distance;
7633                                                         if(max_objects>1)
7634                                                                 for(i=1;i<max_objects;i++){
7635                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7636                                                                         if(closestdist==-1||distance<closestdist){
7637                                                                                 closestdist=distance;
7638                                                                                 closest=i;
7639                                                                         }
7640                                                                 }
7641                                                                 if(closestdist>0&&closest>=0){
7642                                                                         objects.position[closest].y-=500;
7643                                                                 }
7644                                                                 drawmodetogglekeydown=1;
7645                                                 }
7646
7647                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7648                                                         //drawmode++;
7649                                                         //if(drawmode>2)drawmode=0;
7650                                                         if(objects.numobjects<max_objects-1){
7651                                                                 XYZ boxcoords;
7652                                                                 boxcoords.x=player[0].coords.x;
7653                                                                 boxcoords.z=player[0].coords.z;
7654                                                                 boxcoords.y=player[0].coords.y-3;
7655                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7656                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7657                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7658                                                                 float temprotat,temprotat2;
7659                                                                 temprotat=editorrotation;
7660                                                                 temprotat2=editorrotation2;
7661                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7662                                                                 if(temprotat2<0)temprotat2=Random()%360;
7663
7664                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7665                                                                 if(editortype==treetrunktype)
7666                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7667                                                         }
7668
7669                                                         drawmodetogglekeydown=1;
7670                                                 }
7671
7672                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7673                                                         if(numplayers<maxplayers-1){
7674                                                                 player[numplayers].scale=.2*5*player[0].scale;
7675                                                                 player[numplayers].creature=rabbittype;
7676                                                                 player[numplayers].howactive=editoractive;
7677                                                                 player[numplayers].skeleton.id=numplayers;
7678                                                                 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);
7679
7680                                                                 //texsize=512*512*3/texdetail/texdetail;
7681                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7682                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7683
7684                                                                 k=abs(Random()%2)+1;
7685                                                                 if(k==0){
7686                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7687                                                                         player[numplayers].whichskin=0;
7688                                                                 }
7689                                                                 else if(k==1){
7690                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7691                                                                         player[numplayers].whichskin=1;
7692                                                                 }
7693                                                                 else {
7694                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7695                                                                         player[numplayers].whichskin=2;
7696                                                                 }
7697
7698                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7699                                                                 player[numplayers].power=1;
7700                                                                 player[numplayers].speedmult=1;
7701                                                                 player[numplayers].currentanimation=bounceidleanim;
7702                                                                 player[numplayers].targetanimation=bounceidleanim;
7703                                                                 player[numplayers].currentframe=0;
7704                                                                 player[numplayers].targetframe=1;
7705                                                                 player[numplayers].target=0;
7706                                                                 player[numplayers].bled=0;
7707                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
7708
7709                                                                 player[numplayers].targetrotation=player[0].targetrotation;
7710                                                                 player[numplayers].rotation=player[0].rotation;
7711
7712                                                                 player[numplayers].velocity=0;
7713                                                                 player[numplayers].coords=player[0].coords;
7714                                                                 player[numplayers].oldcoords=player[numplayers].coords;
7715                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
7716
7717                                                                 player[numplayers].id=numplayers;
7718                                                                 player[numplayers].skeleton.id=numplayers;
7719                                                                 player[numplayers].updatedelay=0;
7720                                                                 player[numplayers].normalsupdatedelay=0;
7721
7722                                                                 player[numplayers].aitype=passivetype;
7723                                                                 player[numplayers].aitarget=0;
7724
7725                                                                 if(player[0].creature==wolftype){
7726                                                                         headprop=player[0].proportionhead.x/1.1;
7727                                                                         bodyprop=player[0].proportionbody.x/1.1;
7728                                                                         armprop=player[0].proportionarms.x/1.1;
7729                                                                         legprop=player[0].proportionlegs.x/1.1;
7730                                                                 }
7731
7732                                                                 if(player[0].creature==rabbittype){
7733                                                                         headprop=player[0].proportionhead.x/1.2;
7734                                                                         bodyprop=player[0].proportionbody.x/1.05;
7735                                                                         armprop=player[0].proportionarms.x/1.00;
7736                                                                         legprop=player[0].proportionlegs.x/1.1;
7737                                                                 }
7738
7739                                                                 if(player[numplayers].creature==wolftype){
7740                                                                         player[numplayers].proportionhead=1.1*headprop;
7741                                                                         player[numplayers].proportionbody=1.1*bodyprop;
7742                                                                         player[numplayers].proportionarms=1.1*armprop;
7743                                                                         player[numplayers].proportionlegs=1.1*legprop;
7744                                                                 }
7745
7746                                                                 if(player[numplayers].creature==rabbittype){
7747                                                                         player[numplayers].proportionhead=1.2*headprop;
7748                                                                         player[numplayers].proportionbody=1.05*bodyprop;
7749                                                                         player[numplayers].proportionarms=1.00*armprop;
7750                                                                         player[numplayers].proportionlegs=1.1*legprop;
7751                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
7752                                                                 }
7753
7754                                                                 player[numplayers].headless=0;
7755                                                                 player[numplayers].onfire=0;
7756
7757                                                                 if(cellophane){
7758                                                                         player[numplayers].proportionhead.z=0;
7759                                                                         player[numplayers].proportionbody.z=0;
7760                                                                         player[numplayers].proportionarms.z=0;
7761                                                                         player[numplayers].proportionlegs.z=0;
7762                                                                 }
7763
7764                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
7765
7766                                                                 player[numplayers].damagetolerance=200;
7767
7768                                                                 player[numplayers].protectionhead=player[0].protectionhead;
7769                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
7770                                                                 player[numplayers].protectionlow=player[0].protectionlow;
7771                                                                 player[numplayers].armorhead=player[0].armorhead;
7772                                                                 player[numplayers].armorhigh=player[0].armorhigh;
7773                                                                 player[numplayers].armorlow=player[0].armorlow;
7774                                                                 player[numplayers].metalhead=player[0].metalhead;
7775                                                                 player[numplayers].metalhigh=player[0].metalhigh;
7776                                                                 player[numplayers].metallow=player[0].metallow;
7777
7778                                                                 player[numplayers].immobile=player[0].immobile;
7779
7780                                                                 player[numplayers].numclothes=player[0].numclothes;
7781                                                                 if(player[numplayers].numclothes)
7782                                                                         for(i=0;i<player[numplayers].numclothes;i++){
7783                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
7784                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
7785                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
7786                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
7787                                                                                 tintr=player[numplayers].clothestintr[i];
7788                                                                                 tintg=player[numplayers].clothestintg[i];
7789                                                                                 tintb=player[numplayers].clothestintb[i];
7790                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7791                                                                         }
7792                                                                         if(player[numplayers].numclothes){
7793                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
7794                                                                         }
7795
7796                                                                         player[numplayers].power=player[0].power;
7797                                                                         player[numplayers].speedmult=player[0].speedmult;
7798
7799                                                                         player[numplayers].damage=0;
7800                                                                         player[numplayers].permanentdamage=0;
7801                                                                         player[numplayers].superpermanentdamage=0;
7802                                                                         player[numplayers].deathbleeding=0;
7803                                                                         player[numplayers].bleeding=0;
7804                                                                         player[numplayers].numwaypoints=0;
7805                                                                         player[numplayers].waypoint=0;
7806                                                                         player[numplayers].jumppath=0;
7807                                                                         player[numplayers].weaponstuck=-1;
7808                                                                         player[numplayers].weaponactive=-1;
7809                                                                         player[numplayers].num_weapons=0;
7810                                                                         player[numplayers].bloodloss=0;
7811                                                                         player[numplayers].dead=0;
7812
7813                                                                         player[numplayers].loaded=1;
7814
7815                                                                         numplayers++;
7816                                                         }
7817                                                         drawmodetogglekeydown=1;
7818                                                 }
7819
7820                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
7821                                                         if(player[numplayers-1].numwaypoints<90){
7822                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
7823                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
7824                                                                 player[numplayers-1].numwaypoints++;
7825                                                         }
7826                                                         drawmodetogglekeydown=1;
7827                                                 }
7828
7829                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7830                                                         if(numpathpoints<30){
7831                                                                 bool connected,alreadyconnected;
7832                                                                 connected=0;
7833                                                                 if(numpathpoints>1)
7834                                                                         for(i=0;i<numpathpoints;i++){
7835                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
7836                                                                                         alreadyconnected=0;
7837                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
7838                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
7839                                                                                         }
7840                                                                                         if(!alreadyconnected){
7841                                                                                                 numpathpointconnect[pathpointselected]++;
7842                                                                                                 connected=1;
7843                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
7844                                                                                         }
7845                                                                                 }
7846                                                                         }
7847                                                                         if(!connected){
7848                                                                                 numpathpoints++;
7849                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
7850                                                                                 numpathpointconnect[numpathpoints-1]=0;
7851                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
7852                                                                                         numpathpointconnect[pathpointselected]++;
7853                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
7854                                                                                 }
7855                                                                                 pathpointselected=numpathpoints-1;
7856                                                                         }
7857                                                         }
7858                                                         drawmodetogglekeydown=1;
7859                                                 }
7860
7861                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
7862                                                         pathpointselected++;
7863                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
7864                                                         drawmodetogglekeydown=1;
7865                                                 }
7866                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
7867                                                         pathpointselected--;
7868                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
7869                                                         drawmodetogglekeydown=1;
7870                                                 }
7871                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
7872                                                         if(pathpointselected!=-1){
7873                                                                 numpathpoints--;
7874                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
7875                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
7876                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
7877                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
7878                                                                 }
7879                                                                 for(i=0;i<numpathpoints;i++){
7880                                                                         for(j=0;j<numpathpointconnect[i];j++){
7881                                                                                 if(pathpointconnect[i][j]==pathpointselected){
7882                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
7883                                                                                         numpathpointconnect[i]--;
7884                                                                                 }
7885                                                                                 if(pathpointconnect[i][j]==numpathpoints){
7886                                                                                         pathpointconnect[i][j]=pathpointselected;
7887                                                                                 }
7888                                                                         }
7889                                                                 }
7890                                                                 pathpointselected=numpathpoints-1;
7891                                                         }
7892                                                         drawmodetogglekeydown=1;
7893                                                 }
7894
7895                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7896                                                         editorenabled=1-editorenabled;
7897                                                         if(editorenabled){
7898                                                                 player[0].damagetolerance=100000;
7899                                                                 player[0].damage=0;
7900                                                                 player[0].superpermanentdamage=0;
7901                                                                 player[0].bloodloss=0;
7902                                                                 player[0].deathbleeding=0;
7903                                                         }
7904                                                         if(!editorenabled){
7905                                                                 player[0].damagetolerance=200;
7906                                                                 player[0].damage=0;
7907                                                                 player[0].permanentdamage=0;
7908                                                                 player[0].superpermanentdamage=0;
7909                                                                 player[0].bloodloss=0;
7910                                                                 player[0].deathbleeding=0;
7911                                                         }
7912                                                         drawmodetogglekeydown=1;
7913                                                 }
7914
7915                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7916                                                         editortype--;
7917                                                         if(editortype==treeleavestype||editortype==10)editortype--;
7918                                                         if(editortype<0)editortype=firetype;
7919                                                         drawmodetogglekeydown=1;
7920                                                 }
7921
7922                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7923                                                         editortype++;
7924                                                         if(editortype==treeleavestype||editortype==10)editortype++;
7925                                                         if(editortype>firetype)editortype=0;
7926                                                         drawmodetogglekeydown=1;
7927                                                 }
7928
7929                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7930                                                         editorrotation-=multiplier*100;
7931                                                         if(editorrotation<-.01)editorrotation=-.01;
7932                                                         drawmodetogglekeydown=1;
7933                                                 }
7934
7935                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7936                                                         editorrotation+=multiplier*100;
7937                                                         drawmodetogglekeydown=1;
7938                                                 }
7939
7940                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7941                                                         editorsize+=multiplier;
7942                                                         drawmodetogglekeydown=1;
7943                                                 }
7944
7945                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7946                                                         editorsize-=multiplier;
7947                                                         if(editorsize<.1)editorsize=.1;
7948                                                         drawmodetogglekeydown=1;
7949                                                 }
7950
7951
7952                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7953                                                         mapradius-=multiplier*10;
7954                                                 }
7955
7956                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7957                                                         mapradius+=multiplier*10;
7958                                                 }
7959                                                 /*
7960                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7961                                                 mapcenter.x+=multiplier*20;
7962                                                 }
7963
7964                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7965                                                 mapcenter.x-=multiplier*20;
7966                                                 }
7967
7968                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7969                                                 mapcenter.z+=multiplier*20;
7970                                                 }
7971
7972                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7973                                                 mapcenter.z-=multiplier*20;
7974                                                 }
7975                                                 */
7976                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7977                                                         editorrotation2+=multiplier*100;
7978                                                 }
7979
7980                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7981                                                         editorrotation2-=multiplier*100;
7982                                                         if(editorrotation2<-.01)editorrotation2=-.01;
7983                                                 }
7984                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7985                                                         int closest=-1;
7986                                                         float closestdist=-1;
7987                                                         float distance;
7988                                                         for(i=0;i<objects.numobjects;i++){
7989                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
7990                                                                 if(closestdist==-1||distance<closestdist){
7991                                                                         closestdist=distance;
7992                                                                         closest=i;
7993                                                                 }
7994                                                         }
7995                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
7996                                                         drawmodetogglekeydown=1;
7997                                                 }
7998
7999
8000                                                 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)){
8001                                                         drawmodetogglekeydown=0;
8002                                                 }
8003
8004                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8005                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8006                                                         player[0].RagDoll(0);
8007                                                         //player[0].spurt=1;
8008                                                         //player[0].DoDamage(1000);
8009
8010                                                         float gLoc[3];
8011                                                         float vel[3];
8012                                                         gLoc[0]=player[0].coords.x;
8013                                                         gLoc[1]=player[0].coords.y;
8014                                                         gLoc[2]=player[0].coords.z;
8015                                                         vel[0]=player[0].velocity.x;
8016                                                         vel[1]=player[0].velocity.y;
8017                                                         vel[2]=player[0].velocity.z;
8018                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
8019                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8020                                                         OPENAL_SetVolume(channels[whooshsound], 128);
8021                                                         OPENAL_SetPaused(channels[whooshsound], false);
8022                                                         //OPENAL_SetPaused(channels[whooshsound], true);
8023
8024                                                         texturesizetogglekeydown=1;
8025                                                 }
8026
8027                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8028
8029                                                         int closest=-1;
8030                                                         float closestdist=-1;
8031                                                         float distance;
8032                                                         for(i=0;i<objects.numobjects;i++){
8033                                                                 if(objects.type[i]==treeleavestype){
8034                                                                         objects.scale[i]*=.9;
8035                                                                 }
8036                                                         }
8037                                                         texturesizetogglekeydown=1;
8038                                                 }
8039
8040                                                 static XYZ relative;
8041                                                 static int randattack;
8042                                                 //Attack
8043                                                 static bool playerrealattackkeydown=0;
8044
8045                                                 if(!buttons[0])oldbutton=0;
8046                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8047                                                 if(oldattackkey)player[0].attackkeydown=0;
8048                                                 if(oldattackkey)playerrealattackkeydown=0;
8049                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8050                                                 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);
8051                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8052                                                         for(k=0;k<numplayers;k++){
8053                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8054                                                                         player[k].Reverse();
8055                                                         }
8056                                                 }
8057
8058                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8059
8060                                                 for(k=0;k<numplayers;k++){
8061                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8062                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8063                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
8064                                                                 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)){
8065                                                                         player[k].jumppower-=2;
8066                                                                 }
8067                                                                 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)){
8068                                                                         for(i=0;i<numplayers;i++){
8069                                                                                 if(i==k)i++;
8070                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8071                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8072                                                                                                 player[k].targetanimation=dodgebackanim;
8073                                                                                                 player[k].target=0;
8074                                                                                                 player[k].targetframe=0;
8075                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8076                                                                                                 Normalise(&rotatetarget);
8077                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8078                                                                                                 player[k].targetrotation*=360/6.28;
8079                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8080
8081                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8082                                                                                         }
8083                                                                         }
8084                                                                         if(player[k].targetanimation!=dodgebackanim){
8085                                                                                 if(k==0)numflipped++;
8086                                                                                 player[k].targetanimation=backhandspringanim;
8087                                                                                 player[k].target=0;
8088                                                                                 player[k].targetframe=0;
8089                                                                                 player[k].targetrotation=-rotation+180;
8090                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8091                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8092                                                                                 player[k].rotation=player[k].targetrotation;
8093                                                                                 player[k].jumppower-=2;
8094                                                                         }
8095                                                                 }
8096                                                                 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())){
8097                                                                         player[k].hasvictim=0;
8098                                                                         if(numplayers>1)
8099                                                                                 for(i=0;i<numplayers;i++){
8100                                                                                         if(i==k)i++;
8101                                                                                         if(!player[k].hasvictim)
8102                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
8103                                                                                                         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){
8104                                                                                                                 player[k].victim=&player[i];
8105                                                                                                                 player[k].hasvictim=1;
8106                                                                                                                 if(player[k].aitype==playercontrolled){
8107                                                                                                                         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;
8108                                                                                                                         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;
8109                                                                                                                         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;
8110                                                                                                                         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;
8111                                                                                                                         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;
8112                                                                                                                         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;
8113                                                                                                                         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;
8114                                                                                                                         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;
8115                                                                                                                         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;
8116                                                                                                                         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;
8117                                                                                                                 }
8118                                                                                                                 else {
8119                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8120                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8121                                                                                                                                 else randattack=abs(Random()%5);
8122                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8123                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8124                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8125                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8126                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8127                                                                                                                                 }
8128                                                                                                                                 if(player[k].weaponactive!=-1){
8129                                                                                                                                         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;
8130                                                                                                                                         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;
8131                                                                                                                                         //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;
8132                                                                                                                                         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;
8133                                                                                                                                         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;
8134                                                                                                                                         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;
8135                                                                                                                                         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;
8136                                                                                                                                         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;
8137                                                                                                                                 }
8138                                                                                                                         }
8139                                                                                                                 }
8140                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8141                                                                                                         }
8142                                                                                                         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)){
8143                                                                                                                 if(player[k].weaponactive==-1){
8144                                                                                                                         player[i].targetanimation=sneakattackedanim;
8145                                                                                                                         player[i].currentanimation=sneakattackedanim;
8146                                                                                                                         player[k].currentanimation=sneakattackanim;
8147                                                                                                                         player[k].targetanimation=sneakattackanim;
8148                                                                                                                         player[k].oldcoords=player[k].coords;
8149                                                                                                                         player[k].coords=player[i].coords;
8150                                                                                                                 }
8151                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8152                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8153                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8154                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8155                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8156                                                                                                                         player[i].oldcoords=player[i].coords;
8157                                                                                                                         player[i].coords=player[k].coords;
8158                                                                                                                 }
8159                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8160                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8161                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8162                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8163                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8164                                                                                                                         player[i].oldcoords=player[i].coords;
8165                                                                                                                         player[i].coords=player[k].coords;
8166                                                                                                                 }
8167                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8168                                                                                                                         player[k].victim=&player[i];
8169                                                                                                                         player[k].hasvictim=1;
8170                                                                                                                         player[i].targettilt2=0;
8171                                                                                                                         player[i].targetframe=1;
8172                                                                                                                         player[i].currentframe=0;
8173                                                                                                                         player[i].target=0;
8174                                                                                                                         player[i].velocity=0;
8175                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8176                                                                                                                         player[k].currentframe=player[i].currentframe;
8177                                                                                                                         player[k].targetframe=player[i].targetframe;
8178                                                                                                                         player[k].target=player[i].target;
8179                                                                                                                         player[k].velocity=0;
8180                                                                                                                         player[k].targetrotation=player[i].rotation;
8181                                                                                                                         player[k].rotation=player[i].rotation;
8182                                                                                                                         player[i].targetrotation=player[i].rotation;
8183                                                                                                                 }
8184                                                                                                         }
8185                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8186                                                                                                                 oldattackkey=1;
8187                                                                                                                 player[k].targetframe=0;
8188                                                                                                                 player[k].target=0;
8189                                                                                                                 //player[k].velocity=0;
8190
8191                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
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                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8198
8199                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8200                                                                                                                 player[k].lastattack2=player[k].lastattack;
8201                                                                                                                 player[k].lastattack=player[k].targetanimation;
8202                                                                                                                 //player[k].targettilt2=0;
8203                                                                                                                 //slomo=1;
8204                                                                                                                 //slomodelay=.2;
8205                                                                                                         }
8206                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8207                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8208                                                                                                                 Normalise(&rotatetarget);
8209                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8210                                                                                                                 player[k].targetrotation*=360/6.28;
8211                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8212                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8213                                                                                                                 oldattackkey=1;
8214                                                                                                                 player[k].victim=&player[i];
8215                                                                                                                 player[k].hasvictim=1;
8216                                                                                                                 player[i].targetanimation=knifefollowedanim;
8217                                                                                                                 player[i].currentanimation=knifefollowedanim;
8218                                                                                                                 player[i].targettilt2=0;
8219                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8220                                                                                                                 player[i].targetframe=1;
8221                                                                                                                 player[i].currentframe=0;
8222                                                                                                                 player[i].target=0;
8223                                                                                                                 player[i].velocity=0;
8224                                                                                                                 player[k].currentanimation=knifefollowanim;
8225                                                                                                                 player[k].targetanimation=knifefollowanim;
8226                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8227                                                                                                                 player[k].currentframe=player[i].currentframe;
8228                                                                                                                 player[k].targetframe=player[i].targetframe;
8229                                                                                                                 player[k].target=player[i].target;
8230                                                                                                                 player[k].velocity=0;
8231                                                                                                                 player[k].oldcoords=player[k].coords;
8232                                                                                                                 player[i].coords=player[k].coords;
8233                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8234                                                                                                                 player[i].rotation=player[k].targetrotation;
8235                                                                                                                 player[k].rotation=player[k].targetrotation;
8236                                                                                                                 player[i].rotation=player[k].targetrotation;
8237                                                                                                         }
8238                                                                                                 }
8239                                                                                 }
8240                                                                                 bool hasstaff=0;
8241                                                                                 if(player[k].weaponactive!=-1){
8242                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8243                                                                                 }
8244                                                                                 if(numplayers>1)
8245                                                                                         for(i=0;i<numplayers;i++){
8246                                                                                                 if(i==k)i++;
8247                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
8248                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8249                                                                                                                 if(player[i].skeleton.free)
8250                                                                                                                         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)))){
8251                                                                                                                                 player[k].victim=&player[i];
8252                                                                                                                                 player[k].hasvictim=1;
8253                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8254                                                                                                                                         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;
8255                                                                                                                                         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;
8256                                                                                                                                         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;
8257                                                                                                                                 }
8258                                                                                                                                 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){
8259                                                                                                                                         player[k].targetanimation=killanim;
8260                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8261                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8262                                                                                                                                                         terrain.DeleteDecal(j);
8263                                                                                                                                                 }
8264                                                                                                                                         }
8265                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8266                                                                                                                                                 if(objects.model[l].type==decalstype)
8267                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8268                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8269                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8270                                                                                                                                                                 }
8271                                                                                                                                                         }
8272                                                                                                                                         }
8273                                                                                                                                 }
8274                                                                                                                                 if(!player[i].dead||musictype!=2)
8275                                                                                                                                         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)){
8276                                                                                                                                                 player[k].targetanimation=dropkickanim;
8277                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8278                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8279                                                                                                                                                                 terrain.DeleteDecal(j);
8280                                                                                                                                                         }
8281                                                                                                                                                 }
8282                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8283                                                                                                                                                         if(objects.model[l].type==decalstype)
8284                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8285                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8286                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8287                                                                                                                                                                         }
8288                                                                                                                                                                 }
8289                                                                                                                                                 }
8290                                                                                                                                         }
8291                                                                                                                         }
8292                                                                                                                         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)){
8293                                                                                                                                 oldattackkey=1;
8294                                                                                                                                 player[k].targetframe=0;
8295                                                                                                                                 player[k].target=0;
8296                                                                                                                                 //player[k].velocity=0;
8297
8298                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8299                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8300                                                                                                                                         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;
8301                                                                                                                                 }
8302                                                                                                                                 Normalise(&rotatetarget);
8303                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8304                                                                                                                                 player[k].targetrotation*=360/6.28;
8305                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8306
8307                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8308                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8309                                                                                                                                 }
8310
8311                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8312                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8313
8314                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8315                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8316                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8317
8318                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8319                                                                                                                                         player[k].targetrotation+=30;
8320                                                                                                                                 }
8321                                                                                                                                 //player[k].targettilt2=0;
8322                                                                                                                                 //slomo=1;
8323                                                                                                                                 //slomodelay=.2;
8324                                                                                                                         }
8325                                                                                                 }
8326                                                                                         }
8327                                                                                         if(!player[k].hasvictim){
8328                                                                                                 for(i=0;i<numplayers;i++){
8329                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8330                                                                                                                 player[k].victim=&player[i];
8331                                                                                                                 player[k].hasvictim=1;
8332                                                                                                         }
8333                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8334                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8335                                                                                                                         player[k].victim=&player[i];
8336                                                                                                                 }
8337                                                                                                 }
8338                                                                                         }
8339                                                                                         if(player[k].aitype==playercontrolled)
8340                                                                                                 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)){
8341                                                                                                         oldattackkey=1;
8342                                                                                                         player[k].targetanimation=rabbitkickanim;
8343                                                                                                         player[k].targetframe=0;
8344                                                                                                         player[k].target=0;
8345                                                                                                 }
8346                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8347                                                                                                         numattacks++;
8348                                                                                                         bool armedstaff=0;
8349                                                                                                         if(player[k].weaponactive!=-1){
8350                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8351                                                                                                         }
8352                                                                                                         bool armedsword=0;
8353                                                                                                         if(player[k].weaponactive!=-1){
8354                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8355                                                                                                         }
8356                                                                                                         bool armedknife=0;
8357                                                                                                         if(player[k].weaponactive!=-1){
8358                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8359                                                                                                         }
8360                                                                                                         if(armedstaff)numstaffattack++;
8361                                                                                                         else if(armedsword)numswordattack++;
8362                                                                                                         else if(armedknife)numknifeattack++;
8363                                                                                                         else numunarmedattack++;
8364                                                                                                 }
8365                                                                 }
8366                                                         }
8367                                                 }
8368
8369                                                 //Collisions
8370                                                 static float collisionradius;
8371                                                 if(numplayers>1)
8372                                                         for(k=0;k<numplayers;k++){
8373                                                                 for(i=k;i<numplayers;i++){
8374                                                                         if(i==k)i++;
8375                                                                         if(i<numplayers)
8376                                                                                 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))
8377                                                                                         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))
8378                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8379                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8380                                                                                                                 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)
8381                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8382                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8383                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8384                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8385                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8386                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8387                                                                                                                                                                         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)){
8388                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8389                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8390                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8391                                                                                                                                                                                 }
8392                                                                                                                                                                         }
8393
8394                                                                                                                                                                         tempcoords1=player[i].coords;
8395                                                                                                                                                                         tempcoords2=player[k].coords;
8396                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8397                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8398                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8399                                                                                                                                                                         if(player[0].hasvictim)
8400                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8401                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
8402                                                                                                                                                                                 if(k==0)
8403                                                                                                                                                                                         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)){
8404                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8405                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8406                                                                                                                                                                                                 player[i].skeleton.free=0;
8407                                                                                                                                                                                                 player[i].rotation=0;
8408                                                                                                                                                                                                 player[i].RagDoll(0);
8409                                                                                                                                                                                                 player[i].DoDamage(20);
8410                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8411                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8412                                                                                                                                                                                                 player[k].lastcollide=1;
8413                                                                                                                                                                                         }
8414                                                                                                                                                                                         if(i==0)
8415                                                                                                                                                                                                 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)){
8416                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8417                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8418                                                                                                                                                                                                         player[k].skeleton.free=0;
8419                                                                                                                                                                                                         player[k].rotation=0;
8420                                                                                                                                                                                                         player[k].RagDoll(0);
8421                                                                                                                                                                                                         player[k].DoDamage(20);
8422                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8423                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8424                                                                                                                                                                                                         player[i].lastcollide=1;
8425                                                                                                                                                                                                 }
8426
8427                                                                                                                                                                                                 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)){
8428                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8429                                                                                                                                                                                                         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))
8430                                                                                                                                                                                                                 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))){
8431                                                                                                                                                                                                                         //If hit by body
8432                                                                                                                                                                                                                         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)){
8433                                                                                                                                                                                                                                 static float gLoc[3];
8434                                                                                                                                                                                                                                 static float vel[3];
8435                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8436                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8437                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8438                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8439                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8440                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8441                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8442                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
8443                                                                                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8444                                                                                                                                                                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 256);
8445                                                                                                                                                                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
8446                                                                                                                                                                                                                                 }
8447                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8448                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8449
8450                                                                                                                                                                                                                                 player[i].RagDoll(0);
8451                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8452                                                                                                                                                                                                                                         bonus=aimbonus;
8453                                                                                                                                                                                                                                         bonustime=0;
8454                                                                                                                                                                                                                                         bonusvalue=150;
8455                                                                                                                                                                                                                                 }
8456                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8457                                                                                                                                                                                                                                 player[k].RagDoll(0);
8458                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8459                                                                                                                                                                                                                                         bonus=aimbonus;
8460                                                                                                                                                                                                                                         bonustime=0;
8461                                                                                                                                                                                                                                         bonusvalue=150;
8462                                                                                                                                                                                                                                 }
8463                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8464
8465                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8466                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8467                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8468                                                                                                                                                                                                                                 }
8469                                                                                                                                                                                                                                 //}
8470                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8471                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8472                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8473                                                                                                                                                                                                                                 }
8474                                                                                                                                                                                                                                 //}
8475
8476                                                                                                                                                                                                                         }
8477                                                                                                                                                                                                                 }
8478                                                                                                                                                                                                                 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)){
8479                                                                                                                                                                                                                         //If bumped
8480                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8481                                                                                                                                                                                                                                 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)){
8482                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8483                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8484                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8485                                                                                                                                                                                                                                         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);
8486                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8487                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8488                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8489                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8490                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8491                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8492                                                                                                                                                                                                                                                                 player[k].target=0;
8493                                                                                                                                                                                                                                                         }
8494                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8495                                                                                                                                                                                                                                                         {
8496                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8497                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8498                                                                                                                                                                                                                                                                 player[k].target=0;
8499                                                                                                                                                                                                                                                         }
8500                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8501                                                                                                                                                                                                                                                 }
8502                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8503                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8504                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8505                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8506                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8507                                                                                                                                                                                                                                                                         player[i].target=0;
8508                                                                                                                                                                                                                                                                 }
8509                                                                                                                                                                                                                                                                 else
8510                                                                                                                                                                                                                                                                 {
8511                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8512                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8513                                                                                                                                                                                                                                                                         player[i].target=0;
8514                                                                                                                                                                                                                                                                 }
8515                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8516                                                                                                                                                                                                                                                         }
8517                                                                                                                                                                                                                                 }
8518                                                                                                                                                                                                                                 if(hostile){
8519                                                                                                                                                                                                                                         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){
8520                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8521                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8522                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8523                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8524                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8525                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8526                                                                                                                                                                                                                                                 player[k].lastcollide=1;
8527                                                                                                                                                                                                                                                 if(k==0){
8528                                                                                                                                                                                                                                                         bonus=AboveBonus;
8529                                                                                                                                                                                                                                                         bonustime=0;
8530                                                                                                                                                                                                                                                         bonusvalue=50;
8531                                                                                                                                                                                                                                                 }
8532                                                                                                                                                                                                                                         }
8533                                                                                                                                                                                                                                         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){
8534                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8535                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8536                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8537                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8538                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8539                                                                                                                                                                                                                                                 player[k].RagDoll(0);
8540                                                                                                                                                                                                                                                 player[i].lastcollide=1;
8541                                                                                                                                                                                                                                                 if(i==0){
8542                                                                                                                                                                                                                                                         bonus=AboveBonus;
8543                                                                                                                                                                                                                                                         bonustime=0;
8544                                                                                                                                                                                                                                                         bonusvalue=50;
8545                                                                                                                                                                                                                                                 }
8546                                                                                                                                                                                                                                         }
8547                                                                                                                                                                                                                                 }
8548                                                                                                                                                                                                                         }
8549                                                                                                                                                                                                                 }
8550                                                                                                                                                                                                 }
8551                                                                                                                                                                                                 player[i].CheckKick();
8552                                                                                                                                                                                                 player[k].CheckKick();
8553                                                                                                                                                                         }
8554                                                                                                                                                                 }
8555                                                                 }
8556                                                         }
8557
8558                                                         for(k=0;k<numplayers;k++){
8559                                                                 for(i=k;i<numplayers;i++){
8560                                                                         if(i==k)i++;
8561                                                                         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))){
8562                                                                                 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)){
8563                                                                                         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)){
8564                                                                                                 player[i].victim=&player[k];
8565                                                                                                 player[i].targetanimation=jumpreversedanim;
8566                                                                                                 player[i].currentanimation=jumpreversedanim;
8567                                                                                                 player[k].currentanimation=jumpreversalanim;
8568                                                                                                 player[k].targetanimation=jumpreversalanim;
8569                                                                                                 player[i].targettilt2=0;
8570                                                                                                 player[i].currentframe=0;
8571                                                                                                 player[i].targetframe=1;
8572                                                                                                 player[k].currentframe=0;
8573                                                                                                 player[k].targetframe=1;
8574                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8575                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8576                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8577                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8578                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8579                                                                                                         player[k].currentframe=1;
8580                                                                                                         player[k].targetframe=2;
8581                                                                                                         player[i].currentframe=1;
8582                                                                                                         player[i].targetframe=2;
8583                                                                                                 }
8584                                                                                                 player[k].targettilt2=0;
8585                                                                                                 player[i].target=0;
8586                                                                                                 player[i].velocity=0;
8587                                                                                                 player[k].velocity=0;
8588                                                                                                 player[k].oldcoords=player[k].coords;
8589                                                                                                 player[i].coords=player[k].coords;
8590                                                                                                 player[k].targetrotation=player[i].targetrotation;
8591                                                                                                 player[k].rotation=player[i].targetrotation;
8592                                                                                                 player[k].victim=&player[i];
8593                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8594                                                                                         }
8595                                                                                         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)){
8596                                                                                                 player[k].victim=&player[i];
8597                                                                                                 player[k].targetanimation=jumpreversedanim;
8598                                                                                                 player[k].currentanimation=jumpreversedanim;
8599                                                                                                 player[i].currentanimation=jumpreversalanim;
8600                                                                                                 player[i].targetanimation=jumpreversalanim;
8601                                                                                                 player[k].targettilt2=0;
8602                                                                                                 player[i].targettilt2=0;
8603                                                                                                 player[k].currentframe=0;
8604                                                                                                 player[k].targetframe=1;
8605                                                                                                 player[i].currentframe=0;
8606                                                                                                 player[i].targetframe=1;
8607                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8608                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8609                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8610                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8611                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8612                                                                                                         player[k].currentframe=1;
8613                                                                                                         player[k].targetframe=2;
8614                                                                                                         player[i].currentframe=1;
8615                                                                                                         player[i].targetframe=2;
8616                                                                                                 }
8617                                                                                                 player[k].target=0;
8618                                                                                                 player[k].velocity=0;
8619                                                                                                 player[i].velocity=0;
8620                                                                                                 player[i].oldcoords=player[i].coords;
8621                                                                                                 player[k].coords=player[i].coords;
8622                                                                                                 player[i].targetrotation=player[k].targetrotation;
8623                                                                                                 player[i].rotation=player[k].targetrotation;
8624                                                                                                 player[i].victim=&player[k];
8625                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8626                                                                                         }
8627                                                                                 }
8628                                                                         }
8629                                                                 }
8630                                                         }
8631
8632                                                         for(k=0;k<numplayers;k++)
8633                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8634
8635
8636                                                         //pile
8637                                                         /*
8638                                                         XYZ tempdiff;
8639                                                         XYZ tempoldpos;
8640                                                         XYZ temp1,temp2;
8641                                                         bool isgood;
8642                                                         static float checkdelay;
8643                                                         checkdelay-=multiplier;
8644                                                         int m;
8645                                                         static bool checkedcoll[maxplayers][maxplayers];
8646                                                         static bool above[maxplayers];
8647
8648                                                         for(i=0;i<maxplayers;i++){
8649                                                         for(j=0;j<maxplayers;j++){
8650                                                         checkedcoll[i][j]=0;
8651                                                         }
8652                                                         }
8653
8654                                                         if(numplayers>1&&checkdelay<=0){
8655                                                         checkdelay=.015;
8656                                                         for(k=0;k<numplayers;k++){
8657                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8658
8659                                                         for(i=k;i<numplayers;i++){
8660                                                         if(i==k)i++;
8661                                                         if(i<numplayers)
8662                                                         if(!checkedcoll[i][k]){
8663                                                         checkedcoll[i][k]=1;
8664                                                         checkedcoll[k][i]=1;
8665                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8666                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8667                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8668                                                         if(player[i].coords.y>player[k].coords.y-3)
8669                                                         if(player[i].coords.y<player[k].coords.y+3)
8670                                                         if(player[i].coords.x>player[k].coords.x-3)
8671                                                         if(player[i].coords.x<player[k].coords.x+3)
8672                                                         if(player[i].coords.z>player[k].coords.z-3)
8673                                                         if(player[i].coords.z<player[k].coords.z+3)
8674                                                         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)){
8675                                                         int stuck,moving;
8676                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8677                                                         stuck=i;
8678                                                         moving=k;
8679                                                         }
8680                                                         else
8681                                                         {
8682                                                         moving=i;
8683                                                         stuck=k;
8684                                                         }
8685                                                         isgood=1;
8686
8687                                                         if(isgood){
8688                                                         above[moving]=stuck;
8689                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8690                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8691                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8692                                                         {
8693                                                         player[moving].skeleton.joints[l].position.y+=.003;
8694                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8695
8696                                                         }
8697                                                         }
8698                                                         }
8699                                                         }
8700                                                         }
8701                                                         }
8702                                                         }
8703                                                         }
8704                                                         }
8705
8706                                                         */
8707
8708                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
8709                                                                 texturesizetogglekeydown=0;
8710                                                         }
8711
8712                                                         for(k=0;k<numplayers;k++){
8713                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8714                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8715                                                                                 player[k].DoDamage(1000);
8716                                                                         }
8717                                                                 }
8718                                                         }
8719
8720                                                         static bool respawnkeydown;
8721                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
8722                                                                 targetlevel=whichlevel;
8723                                                                 loading=1;
8724                                                                 leveltime=5;
8725                                                         }
8726                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
8727                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
8728
8729
8730
8731
8732                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
8733                                                                 targetlevel++;
8734                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
8735                                                                 loading=1;
8736                                                                 leveltime=5;
8737                                                                 slomotogglekeydown=1;
8738                                                         }
8739
8740                                                         /*
8741                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
8742                                                         //Respawn
8743                                                         OPENAL_SetPaused(channels[whooshsound], true);
8744                                                         changedelay=0;
8745                                                         for(k=0;k<numplayers;k++){
8746                                                         player[k].dead=0;
8747                                                         player[k].damage=0;
8748                                                         player[k].permanentdamage=0;
8749                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
8750                                                         player[k].aitype=passivetype;
8751                                                         }
8752                                                         player[0].aitype=playercontrolled;
8753                                                         }
8754                                                         */
8755
8756                                                         static bool movekey;
8757                                                         static bool connected;
8758                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
8759                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
8760                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
8761                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
8762                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
8763                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
8764
8765                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
8766
8767                 for(int i=0;i<numplayers;i++){
8768                                                                 if(!player[i].skeleton.free){
8769                                                                         oldtargetrotation=player[i].targetrotation;
8770                                                                         if(i==0&&indialogue==-1){
8771                                                                                 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){
8772                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
8773                                                                                         if(cameramode)player[0].targetrotation=0;
8774                                                                                 }
8775
8776                                                                                 facing=0;
8777                                                                                 facing.z=-1;
8778
8779                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
8780                                                                                 if(cameramode){facing=flatfacing;}
8781                                                                                 else{
8782                                                                                         facing=DoRotation(facing,-rotation2,0,0);
8783                                                                                         facing=DoRotation(facing,0,0-rotation,0);
8784                                                                                 }
8785
8786                                                                                 player[0].lookrotation=-rotation;
8787
8788                                                                                 player[i].targetheadrotation=rotation;
8789                                                                                 player[i].targetheadrotation2=rotation2;
8790                                                                         }
8791                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
8792                                                                                 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){
8793                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
8794                                                                                 }
8795
8796                                                                                 facing=0;
8797                                                                                 facing.z=-1;
8798
8799                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
8800
8801                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
8802                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
8803
8804                                                                                 player[i].targetheadrotation=player[i].lookrotation;
8805                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;
8806                                                                         }
8807                                                                         if(indialogue!=-1){
8808                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
8809                                                                                 Normalise(&rotatetarget);
8810                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
8811                                                                                 player[i].targetheadrotation*=360/6.28;
8812                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
8813
8814                                                                                 player[i].targetheadrotation*=-1;
8815                                                                                 player[i].targetheadrotation+=180;
8816                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
8817                                                                         }
8818
8819                                                                         bool pause;
8820
8821                                                                         if(leveltime<.5)
8822                                                                                 numenvsounds=0;
8823
8824                                                                         player[i].avoidsomething=0;
8825
8826                                                                         for(j=0;j<objects.numobjects;j++){
8827                                                                                 if(objects.onfire[j]){
8828                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
8829                                                                                         {
8830                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
8831                                                                                                         player[i].collided=0;
8832                                                                                                         player[i].avoidcollided=1;
8833                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
8834                                                                                                                 player[i].avoidwhere=objects.position[j];
8835                                                                                                 }
8836                                                                                         }
8837                                                                                 }
8838                                                                         }
8839
8840                                                                         //Add avoidwhere to players
8841
8842                                                                         for(j=0;j<numplayers;j++){
8843                                                                                 if(player[j].onfire){
8844                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
8845                                                                                         {
8846                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
8847                                                                                                         player[i].collided=0;
8848                                                                                                         player[i].avoidcollided=1;
8849                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
8850                                                                                                                 player[i].avoidwhere=objects.position[j];
8851                                                                                                 }
8852                                                                                         }
8853                                                                                 }
8854                                                                         }
8855
8856                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
8857                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
8858                                                                                 player[i].jumpclimb=0;
8859                                                                                 //AI
8860                                                                                 if(editorenabled)player[i].stunned=1;
8861
8862                                                                                 player[i].pause=0;
8863                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
8864                                                                                 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;
8865
8866                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
8867                                                                                 player[i].forwardkeydown=0;
8868                                                                                 player[i].leftkeydown=0;
8869                                                                                 player[i].backkeydown=0;
8870                                                                                 player[i].rightkeydown=0;
8871                                                                                 player[i].crouchkeydown=0;
8872                                                                                 player[i].attackkeydown=0;
8873                                                                                 player[i].jumpkeydown=0;
8874                                                                                 player[i].throwkeydown=0;
8875                                                                                 }*/
8876
8877                                                                                 if(player[i].aitype==pathfindtype){
8878                                                                                         if(player[i].finalpathfindpoint==-1){
8879                                                                                                 float closestdistance;
8880                                                                                                 float tempdist;
8881                                                                                                 int closest;
8882                                                                                                 XYZ colpoint;
8883                                                                                                 closest=-1;
8884                                                                                                 closestdistance=-1;
8885                                                                                                 for(j=0;j<numpathpoints;j++){
8886                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
8887                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
8888                                                                                                                 closest=j;
8889                                                                                                                 player[i].finaltarget=pathpoint[j];
8890                                                                                                         }
8891                                                                                                 }
8892                                                                                                 player[i].finalpathfindpoint=closest;
8893                                                                                                 for(j=0;j<numpathpoints;j++){
8894                                                                                                         if(numpathpointconnect[j])
8895                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8896                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
8897                                                                                                                         if(tempdist*tempdist<closestdistance){
8898                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
8899                                                                                                                                         closestdistance=tempdist*tempdist;
8900                                                                                                                                         closest=j;
8901                                                                                                                                         player[i].finaltarget=colpoint;
8902                                                                                                                                 }
8903                                                                                                                         }
8904                                                                                                                 }
8905                                                                                                 }
8906                                                                                                 player[i].finalpathfindpoint=closest;
8907
8908                                                                                         }
8909                                                                                         if(player[i].targetpathfindpoint==-1){
8910                                                                                                 float closestdistance;
8911                                                                                                 float tempdist;
8912                                                                                                 int closest;
8913                                                                                                 XYZ colpoint;
8914                                                                                                 closest=-1;
8915                                                                                                 closestdistance=-1;
8916                                                                                                 if(player[i].lastpathfindpoint==-1){
8917                                                                                                         for(j=0;j<numpathpoints;j++){
8918                                                                                                                 if(j!=player[i].lastpathfindpoint)
8919                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
8920                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
8921                                                                                                                                 closest=j;
8922                                                                                                                         }
8923                                                                                                         }
8924                                                                                                         player[i].targetpathfindpoint=closest;
8925                                                                                                         for(j=0;j<numpathpoints;j++){
8926                                                                                                                 if(j!=player[i].lastpathfindpoint)
8927                                                                                                                         if(numpathpointconnect[j])
8928                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8929                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
8930                                                                                                                                         if(tempdist*tempdist<closestdistance){
8931                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
8932                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
8933                                                                                                                                                         closestdistance=tempdist*tempdist;
8934                                                                                                                                                         closest=j;
8935                                                                                                                                                         //}
8936                                                                                                                                                 }
8937                                                                                                                                         }
8938                                                                                                                                 }
8939                                                                                                         }
8940                                                                                                         player[i].targetpathfindpoint=closest;
8941                                                                                                 }
8942                                                                                                 else
8943                                                                                                 {
8944                                                                                                         for(j=0;j<numpathpoints;j++){
8945                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
8946                                                                                                                 {
8947                                                                                                                         connected=0;
8948                                                                                                                         if(numpathpointconnect[j])
8949                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8950                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
8951                                                                                                                                 }
8952                                                                                                                                 if(!connected)
8953                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
8954                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
8955                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
8956                                                                                                                                                 }
8957                                                                                                                                                 if(connected){
8958                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
8959                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
8960                                                                                                                                                                 closestdistance=tempdist;
8961                                                                                                                                                                 closest=j;
8962                                                                                                                                                         }
8963                                                                                                                                                 }
8964                                                                                                                 }
8965                                                                                                         }
8966                                                                                                         player[i].targetpathfindpoint=closest;
8967                                                                                                 }
8968                                                                                         }
8969                                                                                         player[i].losupdatedelay-=multiplier;
8970
8971                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
8972                                                                                         Normalise(&rotatetarget);
8973                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
8974                                                                                         player[i].targetrotation*=360/6.28;
8975                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
8976                                                                                         player[i].lookrotation=player[i].targetrotation;
8977                                                                                         //player[i].aiupdatedelay=.05;
8978
8979                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
8980                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
8981                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
8982                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
8983                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
8984                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
8985                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
8986                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
8987                                                                                                 player[i].targetpathfindpoint=-1;
8988                                                                                         }
8989                                                                                         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){
8990                                                                                                 player[i].aitype=passivetype;
8991                                                                                         }
8992
8993                                                                                         player[i].forwardkeydown=1;
8994                                                                                         player[i].leftkeydown=0;
8995                                                                                         player[i].backkeydown=0;
8996                                                                                         player[i].rightkeydown=0;
8997                                                                                         player[i].crouchkeydown=0;
8998                                                                                         player[i].attackkeydown=0;
8999                                                                                         player[i].throwkeydown=0;
9000
9001                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9002
9003                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9004                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9005
9006                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9007                                                                                                 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))
9008                                                                                                         player[i].aitype=attacktypecutoff;
9009                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9010                                                                                                         player[i].aitype=attacktypecutoff;
9011
9012                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9013                                                                                                         player[i].losupdatedelay=.2;
9014                                                                                                         for(j=0;j<numplayers;j++){
9015                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9016                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9017                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9018                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9019                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9020                                                                                                                                                         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)){
9021                                                                                                                                                                 player[i].aitype=searchtype;
9022                                                                                                                                                                 player[i].lastchecktime=12;
9023                                                                                                                                                                 player[i].lastseen=player[j].coords;
9024                                                                                                                                                                 player[i].lastseentime=12;
9025                                                                                                                                                         }
9026                                                                                                                 }
9027                                                                                                         }
9028                                                                                                 }
9029                                                                                         }
9030                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9031                                                                                                 if(player[i].creature!=wolftype){
9032                                                                                                         player[i].stunned=.6;
9033                                                                                                         player[i].surprised=.6;
9034                                                                                                 }
9035                                                                                         }
9036                                                                                 }
9037
9038                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9039                                                                                         player[i].howactive=typeactive;
9040                                                                                 }
9041
9042                                                                                 if(player[i].aitype==passivetype){
9043                                                                                         player[i].aiupdatedelay-=multiplier;
9044                                                                                         player[i].losupdatedelay-=multiplier;
9045                                                                                         player[i].lastseentime+=multiplier;
9046                                                                                         player[i].pausetime-=multiplier;
9047                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9048
9049                                                                                         if(player[i].aiupdatedelay<0){
9050                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9051                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9052                                                                                                         Normalise(&rotatetarget);
9053                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9054                                                                                                         player[i].targetrotation*=360/6.28;
9055                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9056                                                                                                         player[i].lookrotation=player[i].targetrotation;
9057                                                                                                         player[i].aiupdatedelay=.05;
9058
9059                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9060                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9061                                                                                                                 player[i].waypoint++;
9062                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9063
9064                                                                                                         }
9065                                                                                                 }
9066
9067                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9068                                                                                                 else player[i].forwardkeydown=0;
9069                                                                                                 player[i].leftkeydown=0;
9070                                                                                                 player[i].backkeydown=0;
9071                                                                                                 player[i].rightkeydown=0;
9072                                                                                                 player[i].crouchkeydown=0;
9073                                                                                                 player[i].attackkeydown=0;
9074                                                                                                 player[i].throwkeydown=0;
9075
9076                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9077                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9078                                                                                                         else{
9079                                                                                                                 XYZ leftpos,rightpos;
9080                                                                                                                 float leftdist,rightdist;
9081                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9082                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9083                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9084                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9085                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9086                                                                                                                 else player[i].targetrotation-=90;
9087                                                                                                         }
9088                                                                                                 }
9089                                                                                         }
9090                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9091                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9092
9093
9094                                                                                         if(!editorenabled){
9095                                                                                                 if(player[i].howactive<typesleeping)
9096                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9097                                                                                                                 for(j=0;j<numenvsounds;j++){
9098                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9099                                                                                                                                 player[i].aitype=attacktypecutoff;
9100                                                                                                                         }
9101                                                                                                                 }
9102
9103                                                                                                                 if(player[i].howactive==typesleeping)
9104                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9105                                                                                                                                 for(j=0;j<numenvsounds;j++){
9106                                                                                                                                         if(envsoundvol[j]>14)
9107                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9108                                                                                                                                                         player[i].aitype=attacktypecutoff;
9109                                                                                                                                                 }
9110                                                                                                                                 }
9111
9112                                                                                                                                 if(player[i].aitype!=passivetype){
9113                                                                                                                                         if(player[i].howactive==typesleeping){
9114                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9115                                                                                                                                                 player[i].targetframe=0;
9116                                                                                                                                                 player[i].target=0;
9117                                                                                                                                         }
9118
9119                                                                                                                                         player[i].howactive=typeactive;
9120                                                                                                                                 }
9121                                                                                         }
9122
9123                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9124                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9125                                                                                                         player[i].aitype=attacktypecutoff;
9126                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9127                                                                                                         player[i].aitype=attacktypecutoff;
9128
9129                                                                                                 if(player[i].creature==wolftype){
9130                                                                                                         XYZ windsmell;
9131                                                                                                         float smelldistance;
9132                                                                                                         smelldistance=50;
9133                                                                                                         for(j=0;j<numplayers;j++){
9134                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9135                                                                                                                         if(j==0&&player[j].num_weapons>0){
9136                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9137                                                                                                                                 if(player[j].num_weapons==2)
9138                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9139                                                                                                                         }
9140                                                                                                                         if(j!=0){
9141                                                                                                                                 smelldistance=100;
9142                                                                                                                         }
9143                                                                                                                         windsmell=windvector;
9144                                                                                                                         Normalise(&windsmell);
9145                                                                                                                         windsmell=windsmell*2+player[j].coords;
9146                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9147                                                                                                                                 player[i].aitype=attacktypecutoff;
9148                                                                                                                 }
9149                                                                                                         }
9150                                                                                                 }
9151
9152                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9153                                                                                                         player[i].losupdatedelay=.2;
9154                                                                                                         for(j=0;j<numplayers;j++){
9155                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9156                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9157                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9158                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9159                                                                                                                                                 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)){
9160                                                                                                                                                         player[i].lastseentime-=.2;
9161                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9162                                                                                                                                                         else player[i].lastseentime-=.6;
9163                                                                                                                                                 }
9164                                                                                                                                                 if(player[i].lastseentime<=0){
9165                                                                                                                                                         player[i].aitype=searchtype;
9166                                                                                                                                                         player[i].lastchecktime=12;
9167                                                                                                                                                         player[i].lastseen=player[j].coords;
9168                                                                                                                                                         player[i].lastseentime=12;
9169                                                                                                                                                 }
9170                                                                                                                 }
9171                                                                                                         }
9172                                                                                                 }
9173                                                                                         }
9174                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9175                                                                                                 if(player[i].creature!=wolftype){
9176                                                                                                         player[i].stunned=.6;
9177                                                                                                         player[i].surprised=.6;
9178                                                                                                 }
9179                                                                                                 if(player[i].creature==wolftype){
9180                                                                                                         player[i].stunned=.47;
9181                                                                                                         player[i].surprised=.47;
9182                                                                                                 }
9183                                                                                                 numseen++;
9184                                                                                         }
9185                                                                                 }
9186
9187                                                                                 if(player[i].aitype==searchtype){
9188                                                                                         player[i].aiupdatedelay-=multiplier;
9189                                                                                         player[i].losupdatedelay-=multiplier;
9190                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9191                                                                                         player[i].lastchecktime-=multiplier;
9192
9193                                                                                         if(player[i].isRun()&&!player[i].onground){
9194                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9195                                                                                                         test2=player[i].coords+player[i].facing;
9196                                                                                                         test2.y+=5;
9197                                                                                                         test=player[i].coords+player[i].facing;
9198                                                                                                         test.y-=10;
9199                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9200                                                                                                         if(j==-1)j=checkcollide(test2,test);
9201                                                                                                         if(j==-1){
9202                                                                                                                 player[i].velocity=0;
9203                                                                                                                 player[i].targetanimation=player[i].getStop();
9204                                                                                                                 player[i].targetframe=0;
9205                                                                                                                 player[i].target=0;
9206                                                                                                                 player[i].targetrotation+=180;
9207                                                                                                                 player[i].stunned=.5;
9208                                                                                                                 //player[i].aitype=passivetype;
9209                                                                                                                 player[i].aitype=pathfindtype;
9210                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9211                                                                                                                 player[i].finalpathfindpoint=-1;
9212                                                                                                                 player[i].targetpathfindpoint=-1;
9213                                                                                                                 player[i].lastpathfindpoint=-1;
9214                                                                                                                 player[i].lastpathfindpoint2=-1;
9215                                                                                                                 player[i].lastpathfindpoint3=-1;
9216                                                                                                                 player[i].lastpathfindpoint4=-1;
9217                                                                                                         }
9218                                                                                                         else player[i].laststanding=j;
9219                                                                                                 }
9220                                                                                         }
9221                                                                                         if(player[i].aiupdatedelay<0){
9222                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9223                                                                                                 Normalise(&rotatetarget);
9224                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9225                                                                                                 player[i].targetrotation*=360/6.28;
9226                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9227                                                                                                 player[i].lookrotation=player[i].targetrotation;
9228                                                                                                 player[i].aiupdatedelay=.05;
9229                                                                                                 player[i].forwardkeydown=1;
9230
9231                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9232                                                                                                         player[i].forwardkeydown=0;
9233                                                                                                         player[i].aiupdatedelay=1;
9234                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9235                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9236                                                                                                         player[i].lastchecktime=3;
9237                                                                                                 }
9238
9239                                                                                                 player[i].leftkeydown=0;
9240                                                                                                 player[i].backkeydown=0;
9241                                                                                                 player[i].rightkeydown=0;
9242                                                                                                 player[i].crouchkeydown=0;
9243                                                                                                 player[i].attackkeydown=0;
9244                                                                                                 player[i].throwkeydown=0;
9245
9246                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9247                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9248                                                                                                         else{
9249                                                                                                                 XYZ leftpos,rightpos;
9250                                                                                                                 float leftdist,rightdist;
9251                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9252                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9253                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9254                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9255                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9256                                                                                                                 else player[i].targetrotation-=90;
9257                                                                                                         }
9258                                                                                                 }
9259                                                                                         }
9260                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9261                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9262
9263                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9264                                                                                                 for(j=0;j<numenvsounds;j++){
9265                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9266                                                                                                                 player[i].aitype=attacktypecutoff;
9267                                                                                                         }
9268                                                                                                 }
9269
9270                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9271                                                                                                         player[i].losupdatedelay=.2;
9272                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9273                                                                                                         {player[i].aitype=attacktypecutoff;
9274                                                                                                         player[i].lastseentime=1;}
9275                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9276                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9277                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9278                                                                                                                                 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)){
9279                                                                                                                                         player[i].aitype=attacktypecutoff;
9280                                                                                                                                         player[i].lastseentime=1;
9281                                                                                                                                 }
9282                                                                                                 }
9283                                                                                                 if(player[i].lastseentime<0){
9284                                                                                                         //player[i].aitype=passivetype;
9285                                                                                                         numescaped++;
9286                                                                                                         player[i].aitype=pathfindtype;
9287                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9288                                                                                                         player[i].finalpathfindpoint=-1;
9289                                                                                                         player[i].targetpathfindpoint=-1;
9290                                                                                                         player[i].lastpathfindpoint=-1;
9291                                                                                                         player[i].lastpathfindpoint2=-1;
9292                                                                                                         player[i].lastpathfindpoint3=-1;
9293                                                                                                         player[i].lastpathfindpoint4=-1;
9294                                                                                                 }
9295                                                                                 }
9296
9297                                                                                 if(player[i].aitype!=gethelptype){
9298                                                                                         player[i].runninghowlong=0;
9299                                                                                 }
9300
9301                                                                                 if(player[i].aitype==gethelptype){
9302                                                                                         player[i].runninghowlong+=multiplier;
9303                                                                                         player[i].aiupdatedelay-=multiplier;
9304
9305                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9306                                                                                                 player[i].aiupdatedelay=.2;
9307
9308                                                                                                 int closest;
9309                                                                                                 float closestdist;
9310                                                                                                 closest=-1;
9311                                                                                                 closestdist=-1;
9312                                                                                                 float distance;
9313
9314                                                                                                 if(!player[i].ally){
9315                                                                                                         for(j=0;j<numplayers;j++){
9316                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9317                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9318                                                                                                                         if(closestdist==-1||distance<closestdist){
9319                                                                                                                                 closestdist=distance;
9320                                                                                                                                 closest=j;
9321                                                                                                                         }
9322                                                                                                                         closest=j;
9323                                                                                                                 }
9324                                                                                                         }
9325                                                                                                         if(closest!=-1)player[i].ally=closest;
9326                                                                                                         else player[i].ally=0;
9327                                                                                                         player[i].lastseen=player[0].coords;
9328                                                                                                         player[i].lastseentime=12;
9329                                                                                                 }
9330
9331
9332                                                                                                 player[i].lastchecktime=12;
9333                                                                                                 //player[i].lastseentime-=.5;
9334
9335                                                                                                 facing=player[i].coords;
9336                                                                                                 flatfacing=player[player[i].ally].coords;
9337                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9338                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9339                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9340                                                                                                         player[i].lastseentime-=.1;
9341
9342                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9343                                                                                                         player[i].aitype=searchtype;
9344                                                                                                         player[i].lastseentime=12;
9345                                                                                                 }
9346
9347                                                                                                 if(player[i].ally>0){
9348                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9349                                                                                                         Normalise(&rotatetarget);
9350                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9351                                                                                                         player[i].targetrotation*=360/6.28;
9352                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9353                                                                                                         player[i].lookrotation=player[i].targetrotation;
9354                                                                                                         player[i].aiupdatedelay=.05;
9355                                                                                                         player[i].forwardkeydown=1;
9356
9357                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9358                                                                                                                 player[i].aitype=searchtype;
9359                                                                                                                 player[i].lastseentime=12;
9360                                                                                                                 player[player[i].ally].aitype=searchtype;
9361                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9362                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9363                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9364                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9365                                                                                                                 }
9366                                                                                                         }
9367
9368                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9369                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9370                                                                                                                 else{
9371                                                                                                                         XYZ leftpos,rightpos;
9372                                                                                                                         float leftdist,rightdist;
9373                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9374                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9375                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9376                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9377                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9378                                                                                                                         else player[i].targetrotation-=90;
9379                                                                                                                 }
9380                                                                                                         }
9381                                                                                                 }
9382
9383                                                                                                 player[i].leftkeydown=0;
9384                                                                                                 player[i].backkeydown=0;
9385                                                                                                 player[i].rightkeydown=0;
9386                                                                                                 player[i].crouchkeydown=0;
9387                                                                                                 player[i].attackkeydown=0;
9388                                                                                         }
9389                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9390                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9391                                                                                 }
9392
9393                                                                                 if(player[i].aitype==getweapontype){
9394                                                                                         player[i].aiupdatedelay-=multiplier;
9395                                                                                         player[i].lastchecktime-=multiplier;
9396
9397                                                                                         if(player[i].aiupdatedelay<0){
9398                                                                                                 player[i].aiupdatedelay=.2;
9399
9400                                                                                                 int closest;
9401                                                                                                 float closestdist;
9402                                                                                                 closest=-1;
9403                                                                                                 closestdist=-1;
9404                                                                                                 float distance;
9405
9406                                                                                                 if(player[i].ally<0){
9407                                                                                                         for(j=0;j<weapons.numweapons;j++){
9408                                                                                                                 if(weapons.owner[j]==-1){
9409                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9410                                                                                                                         if(closestdist==-1||distance<closestdist){
9411                                                                                                                                 closestdist=distance;
9412                                                                                                                                 closest=j;
9413                                                                                                                         }
9414                                                                                                                         closest=j;
9415                                                                                                                 }
9416                                                                                                         }
9417                                                                                                         if(closest!=-1)player[i].ally=closest;
9418                                                                                                         else player[i].ally=-1;
9419                                                                                                 }
9420
9421                                                                                                 player[i].lastseentime=12;
9422
9423                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9424                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9425                                                                                                                 player[i].aitype=attacktypecutoff;
9426                                                                                                                 player[i].lastseentime=1;
9427                                                                                                         }
9428                                                                                                         if(!player[0].dead)
9429                                                                                                                 if(player[i].ally>=0){
9430                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9431                                                                                                                                 player[i].aitype=attacktypecutoff;
9432                                                                                                                                 player[i].lastseentime=1;
9433                                                                                                                         }
9434                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9435                                                                                                                         Normalise(&rotatetarget);
9436                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9437                                                                                                                         player[i].targetrotation*=360/6.28;
9438                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9439                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9440                                                                                                                         player[i].aiupdatedelay=.05;
9441                                                                                                                         player[i].forwardkeydown=1;
9442
9443
9444                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9445                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9446                                                                                                                                 else{
9447                                                                                                                                         XYZ leftpos,rightpos;
9448                                                                                                                                         float leftdist,rightdist;
9449                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9450                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9451                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9452                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9453                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9454                                                                                                                                         else player[i].targetrotation-=90;
9455                                                                                                                                 }
9456                                                                                                                         }
9457                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9458                                                                                                                         if(abs(Random()%6)){
9459                                                                                                                         player[i].crouchkeydown=1;
9460                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9461                                                                                                                         if(player[i].isRun()){
9462                                                                                                                         player[i].targetframe=0;
9463                                                                                                                         player[i].target=0;
9464                                                                                                                         player[i].targetanimation=sneakanim;
9465                                                                                                                         }
9466                                                                                                                         }
9467                                                                                                                         else player[i].forwardkeydown=0;
9468                                                                                                                         }
9469                                                                                                                         else player[i].crouchkeydown=0;
9470                                                                                                                         }
9471                                                                                                                         else player[i].crouchkeydown=0;*/
9472                                                                                                                 }
9473
9474                                                                                                                 player[i].leftkeydown=0;
9475                                                                                                                 player[i].backkeydown=0;
9476                                                                                                                 player[i].rightkeydown=0;
9477                                                                                                                 player[i].attackkeydown=0;
9478                                                                                                                 player[i].throwkeydown=1;
9479                                                                                                                 player[i].crouchkeydown=0;
9480                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9481                                                                                                                 player[i].drawkeydown=0;
9482                                                                                         }
9483                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9484                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9485                                                                                 }
9486
9487                                                                                 if(player[i].aitype==attacktypecutoff){
9488                                                                                         player[i].aiupdatedelay-=multiplier;
9489                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9490                                                                                                 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)){
9491                                                                                                         player[i].attackkeydown=0;
9492                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9493                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9494                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9495                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9496                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9497                                                                                                                                 else player[i].targetanimation=rollanim;
9498                                                                                                                                 player[i].target=0;
9499                                                                                                                                 player[i].targetframe=0;
9500                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9501                                                                                                                                 player[i].wentforweapon=0;
9502                                                                                                                         }
9503                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9504                                                                                                                                 player[i].targetanimation=flipanim;
9505                                                                                                                                 player[i].target=0;
9506                                                                                                                                 player[i].targetframe=0;
9507                                                                                                                         }
9508                                                                                                                 }
9509                                                                                                         }
9510                                                                                                         player[i].forwardkeydown=0;
9511                                                                                                         player[i].aiupdatedelay=.02;
9512                                                                                                 }
9513                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9514                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9515                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9516                                                                                                 }
9517                                                                                                 if(player[i].wentforweapon<3)
9518                                                                                                         for(j=0;j<weapons.numweapons;j++){
9519                                                                                                                 if(player[i].creature!=wolftype)
9520                                                                                                                         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){
9521                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9522                                                                                                                                         player[i].wentforweapon++;
9523                                                                                                                                         player[i].lastchecktime=6;
9524                                                                                                                                         player[i].aitype=getweapontype;
9525                                                                                                                                         player[i].ally=-1;
9526                                                                                                                                 }
9527                                                                                                                         }
9528                                                                                                         }
9529                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9530                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9531                                                                                                                         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)))){
9532                                                                                                                                 player[i].crouchkeydown=1;
9533                                                                                                                         }
9534                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9535                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9536                                                                                                                                         test2=player[i].coords+player[i].facing;
9537                                                                                                                                         test2.y+=5;
9538                                                                                                                                         test=player[i].coords+player[i].facing;
9539                                                                                                                                         test.y-=10;
9540                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9541                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9542                                                                                                                                         if(j==-1){
9543                                                                                                                                                 player[i].velocity=0;
9544                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9545                                                                                                                                                 player[i].targetframe=0;
9546                                                                                                                                                 player[i].target=0;
9547                                                                                                                                                 player[i].targetrotation+=180;
9548                                                                                                                                                 player[i].stunned=.5;
9549                                                                                                                                                 //player[i].aitype=passivetype;
9550                                                                                                                                                 player[i].aitype=pathfindtype;
9551                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9552                                                                                                                                                 player[i].finalpathfindpoint=-1;
9553                                                                                                                                                 player[i].targetpathfindpoint=-1;
9554                                                                                                                                                 player[i].lastpathfindpoint=-1;
9555                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9556                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9557                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9558                                                                                                                                         }
9559                                                                                                                                         else player[i].laststanding=j;
9560                                                                                                                                 }
9561                                                                                                                         }
9562                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9563                                                                                                                                 player[i].aitype=pathfindtype;
9564                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9565                                                                                                                                 player[i].finalpathfindpoint=-1;
9566                                                                                                                                 player[i].targetpathfindpoint=-1;
9567                                                                                                                                 player[i].lastpathfindpoint=-1;
9568                                                                                                                                 player[i].lastpathfindpoint2=-1;
9569                                                                                                                                 player[i].lastpathfindpoint3=-1;
9570                                                                                                                                 player[i].lastpathfindpoint4=-1;
9571                                                                                                                         }
9572                                                                                                                         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){
9573                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9574                                                                                                                                 else player[i].drawkeydown=0;
9575                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9576                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9577                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9578                                                                                                                                         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;
9579                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9580                                                                                                                                 Normalise(&rotatetarget);
9581                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9582                                                                                                                                 player[i].targetrotation*=360/6.28;
9583                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9584                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9585                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9586
9587                                                                                                                                 oldkey=player[i].forwardkeydown;
9588                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9589                                                                                                                                 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;
9590                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9591                                                                                                                                 else player[i].forwardkeydown=0;
9592                                                                                                                                 if(player[0].dead){
9593                                                                                                                                         player[i].forwardkeydown=0;
9594                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9595                                                                                                                                         if(Random()%100==0){
9596                                                                                                                                                 player[i].aitype=pathfindtype;
9597                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9598                                                                                                                                                 player[i].finalpathfindpoint=-1;
9599                                                                                                                                                 player[i].targetpathfindpoint=-1;
9600                                                                                                                                                 player[i].lastpathfindpoint=-1;
9601                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9602                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9603                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9604                                                                                                                                         }
9605                                                                                                                                 }
9606                                                                                                                                 player[i].leftkeydown=0;
9607                                                                                                                                 player[i].backkeydown=0;
9608                                                                                                                                 player[i].rightkeydown=0;
9609                                                                                                                                 player[i].crouchkeydown=0;
9610                                                                                                                                 player[i].throwkeydown=0;
9611
9612                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9613                                                                                                                                 /*for(j=0;j<numplayers;j++){
9614                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9615                                                                                                                                 player[i].crouchkeydown=1;
9616                                                                                                                                 }
9617                                                                                                                                 }*/
9618                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9619                                                                                                                                 else player[i].attackkeydown=0;
9620                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9621                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9622                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9623                                                                                                                                 player[i].attackkeydown=0;
9624                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9625                                                                                                                                 player[i].forwardkeydown=0;
9626                                                                                                                                 player[i].aiupdatedelay=.02;
9627                                                                                                                                 }*/
9628
9629                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9630                                                                                                                                         target=-2;
9631                                                                                                                                         for(j=0;j<numplayers;j++){
9632                                                                                                                                                 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)){
9633                                                                                                                                                         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))))){
9634                                                                                                                                                                 if(target>=0)target=-1;
9635                                                                                                                                                                 else target=j;
9636                                                                                                                                                         }
9637                                                                                                                                                 }
9638                                                                                                                                         }
9639                                                                                                                                         if(target>=0)player[target].Reverse();
9640                                                                                                                                 }
9641
9642                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9643                                                                                                                                 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;
9644                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9645                                                                                                                                         player[0].jumpkeydown=0;
9646                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9647                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9648                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9649
9650                                                                                                                                 if(tutoriallevel==1){
9651                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9652                                                                                                                                 }
9653
9654
9655                                                                                                                                 facing=player[i].coords;
9656                                                                                                                                 flatfacing=player[0].coords;
9657                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9658                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9659                                                                                                                                 if(player[i].occluded>=2)
9660                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9661                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9662                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9663                                                                                                                                                         player[i].aitype=searchtype;
9664                                                                                                                                                         player[i].lastchecktime=12;
9665                                                                                                                                                         player[i].lastseen=player[0].coords;
9666                                                                                                                                                         player[i].lastseentime=12;
9667                                                                                                                                                 }
9668                                                                                                                                         }
9669                                                                                                                                         else player[i].lastseentime=1;
9670                                                                                                                         }
9671                                                                                 }
9672                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9673                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9674                                                                                                 test=player[0].coords;
9675                                                                                                 test.y-=40;
9676                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9677                                                                                         }
9678                                                                                 }
9679                                                                                 // NOTE: Ask about logic of this call : NOTE
9680                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9681                                                                                         player[i].stunned>0 ||
9682                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9683                                                                                 {
9684                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9685                                                                                         player[i].targetrotation=player[i].rotation;
9686                                                                                         player[i].forwardkeydown=0;
9687                                                                                         player[i].leftkeydown=0;
9688                                                                                         player[i].backkeydown=0;
9689                                                                                         player[i].rightkeydown=0;
9690                                                                                         player[i].jumpkeydown=0;
9691                                                                                         player[i].attackkeydown=0;
9692                                                                                         player[i].crouchkeydown=0;
9693                                                                                         player[i].throwkeydown=0;
9694                                                                                 }
9695
9696
9697                                                                                 facing=0;
9698                                                                                 facing.z=-1;
9699
9700                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9701                                                                                 facing=flatfacing;
9702
9703                                                                                 if(player[i].aitype==attacktypecutoff){
9704                                                                                         rotatetarget=player[0].coords-player[i].coords;
9705                                                                                         Normalise(&rotatetarget);
9706                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9707                                                                                         player[i].targetheadrotation*=360/6.28;
9708                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9709
9710                                                                                         player[i].targetheadrotation*=-1;
9711                                                                                         player[i].targetheadrotation+=180;
9712                                                                                         //player[i].targetheadrotation2=0;
9713                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9714                                                                                 }
9715                                                                                 else if(player[i].howactive>=typesleeping){
9716                                                                                         player[i].targetheadrotation=player[i].targetrotation;
9717                                                                                         player[i].targetheadrotation2=0;
9718                                                                                 }
9719                                                                                 else {
9720                                                                                         if(player[i].interestdelay<=0){
9721                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
9722                                                                                                 player[i].headtarget=player[i].coords;
9723                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
9724                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
9725                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
9726                                                                                                 player[i].headtarget+=player[i].facing*1.5;
9727                                                                                         }
9728                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
9729                                                                                         Normalise(&rotatetarget);
9730                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9731                                                                                         player[i].targetheadrotation*=360/6.28;
9732                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9733
9734                                                                                         player[i].targetheadrotation*=-1;
9735                                                                                         player[i].targetheadrotation+=180;
9736                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9737                                                                                 }
9738                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
9739                                                                         }
9740                                                                         if(animation[player[i].targetanimation].attack==reversed){
9741                                                                                 //player[i].targetrotation=player[i].rotation;
9742                                                                                 player[i].forwardkeydown=0;
9743                                                                                 player[i].leftkeydown=0;
9744                                                                                 player[i].backkeydown=0;
9745                                                                                 player[i].rightkeydown=0;
9746                                                                                 player[i].jumpkeydown=0;
9747                                                                                 player[i].attackkeydown=0;
9748                                                                                 //player[i].crouchkeydown=0;
9749                                                                                 player[i].throwkeydown=0;
9750                                                                         }
9751
9752                                                                         if(indialogue!=-1){
9753                                                                                 player[i].forwardkeydown=0;
9754                                                                                 player[i].leftkeydown=0;
9755                                                                                 player[i].backkeydown=0;
9756                                                                                 player[i].rightkeydown=0;
9757                                                                                 player[i].jumpkeydown=0;
9758                                                                                 player[i].crouchkeydown=0;
9759                                                                                 player[i].drawkeydown=0;
9760                                                                                 player[i].throwkeydown=0;
9761                                                                         }
9762
9763                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
9764                                                                         if(player[i].collided>1)player[i].collided=1;
9765                                                                         player[i].collided-=multiplier*4;
9766                                                                         player[i].whichdirectiondelay-=multiplier;
9767                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
9768                                                                                 player[i].avoidcollided=-.3;
9769                                                                                 player[i].whichdirection=abs(Random()%2);
9770                                                                                 player[i].whichdirectiondelay=.4;
9771                                                                         }
9772                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
9773                                                                         player[i].avoidcollided-=multiplier/4;
9774                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
9775                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
9776                                                                         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;
9777
9778                                                                         if(!player[i].throwkeydown){
9779                                                                                 player[i].throwtogglekeydown=0;
9780                                                                         }
9781                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
9782                                                                                 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)){
9783                                                                                         for(j=0;j<weapons.numweapons;j++){
9784                                                                                                 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)
9785                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
9786                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
9787                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
9788                                                                                                                                 player[i].throwtogglekeydown=1;
9789                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
9790                                                                                                                                 player[i].target=0;
9791                                                                                                                                 player[i].targetframe=0;
9792                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
9793                                                                                                                                 Normalise(&rotatetarget);
9794                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9795                                                                                                                                 player[i].targetrotation*=360/6.28;
9796                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9797                                                                                                                                 player[i].hasvictim=0;
9798                                                                                                                         }
9799                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9800                                                                                                                                 player[i].throwtogglekeydown=1;
9801                                                                                                                                 player[i].hasvictim=0;
9802
9803                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
9804                                                                                                                                 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))
9805                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
9806                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
9807                                                                                                                                                         float gLoc[3];
9808                                                                                                                                                         float vel[3];
9809                                                                                                                                                         gLoc[0]=player[i].coords.x;
9810                                                                                                                                                         gLoc[1]=player[i].coords.y;
9811                                                                                                                                                         gLoc[2]=player[i].coords.z;
9812                                                                                                                                                         vel[0]=player[i].velocity.x;
9813                                                                                                                                                         vel[1]=player[i].velocity.y;
9814                                                                                                                                                         vel[2]=player[i].velocity.z;
9815                                                                                                                                                         if(weapons.type[j]!=staff){
9816                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9817                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9818                                                                                                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
9819                                                                                                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
9820                                                                                                                                                         }
9821
9822                                                                                                                                                         player[i].weaponactive=0;
9823                                                                                                                                                         weapons.owner[j]=player[i].id;
9824                                                                                                                                                         if(player[i].num_weapons>0){
9825                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9826                                                                                                                                                         }
9827                                                                                                                                                         player[i].num_weapons++;
9828                                                                                                                                                         player[i].weaponids[0]=j;
9829                                                                                                                                                 }
9830                                                                                                                                         }
9831                                                                                                                                         //}
9832                                                                                                                         }
9833                                                                                                                 }
9834                                                                                                                 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){
9835                                                                                                                         if(!player[i].isFlip()){
9836                                                                                                                                 player[i].throwtogglekeydown=1;
9837                                                                                                                                 player[i].targetanimation=removeknifeanim;
9838                                                                                                                                 player[i].target=0;
9839                                                                                                                                 player[i].targetframe=0;
9840                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
9841                                                                                                                                 Normalise(&rotatetarget);
9842                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9843                                                                                                                                 player[i].targetrotation*=360/6.28;
9844                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9845                                                                                                                         }
9846                                                                                                                         if(player[i].isFlip()){
9847                                                                                                                                 player[i].throwtogglekeydown=1;
9848                                                                                                                                 player[i].hasvictim=0;
9849
9850                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
9851                                                                                                                                         if(player[i].weaponactive==-1)
9852                                                                                                                                                 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))
9853                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
9854                                                                                                                                                                 float gLoc[3];
9855                                                                                                                                                                 float vel[3];
9856                                                                                                                                                                 gLoc[0]=player[i].coords.x;
9857                                                                                                                                                                 gLoc[1]=player[i].coords.y;
9858                                                                                                                                                                 gLoc[2]=player[i].coords.z;
9859                                                                                                                                                                 vel[0]=player[i].velocity.x;
9860                                                                                                                                                                 vel[1]=player[i].velocity.y;
9861                                                                                                                                                                 vel[2]=player[i].velocity.z;
9862                                                                                                                                                                 if(weapons.type[k]!=staff){
9863                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9864                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9865                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
9866                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
9867                                                                                                                                                                 }
9868
9869                                                                                                                                                                 player[i].weaponactive=0;
9870                                                                                                                                                                 weapons.owner[k]=player[i].id;
9871                                                                                                                                                                 if(player[i].num_weapons>0){
9872                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9873                                                                                                                                                                 }
9874                                                                                                                                                                 player[i].num_weapons++;
9875                                                                                                                                                                 player[i].weaponids[0]=k;
9876                                                                                                                                                         }
9877                                                                                                                                 }
9878                                                                                                                         }
9879                                                                                                                 }
9880                                                                                                         }
9881                                                                                         }
9882                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9883                                                                                                 if(numplayers>1)
9884                                                                                                         for(j=0;j<numplayers;j++){
9885                                                                                                                 if(player[i].weaponactive==-1)
9886                                                                                                                         if(j!=i)
9887                                                                                                                                 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)){
9888                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
9889                                                                                                                                                 player[i].throwtogglekeydown=1;
9890                                                                                                                                                 player[i].victim=&player[j];
9891                                                                                                                                                 player[i].hasvictim=1;
9892                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
9893                                                                                                                                                 player[i].target=0;
9894                                                                                                                                                 player[i].targetframe=0;
9895                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
9896                                                                                                                                                 Normalise(&rotatetarget);
9897                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9898                                                                                                                                                 player[i].targetrotation*=360/6.28;
9899                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9900                                                                                                                                         }
9901                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9902                                                                                                                                                 player[i].throwtogglekeydown=1;
9903                                                                                                                                                 player[i].victim=&player[j];
9904                                                                                                                                                 player[i].hasvictim=1;
9905                                                                                                                                                 int k = player[j].weaponids[0];
9906                                                                                                                                                 if(player[i].hasvictim){
9907                                                                                                                                                         float gLoc[3];
9908                                                                                                                                                         float vel[3];
9909                                                                                                                                                         gLoc[0]=player[i].coords.x;
9910                                                                                                                                                         gLoc[1]=player[i].coords.y;
9911                                                                                                                                                         gLoc[2]=player[i].coords.z;
9912                                                                                                                                                         vel[0]=player[i].velocity.x;
9913                                                                                                                                                         vel[1]=player[i].velocity.y;
9914                                                                                                                                                         vel[2]=player[i].velocity.z;
9915                                                                                                                                                         bool fleshstuck;
9916                                                                                                                                                         fleshstuck=0;
9917                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
9918                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
9919                                                                                                                                                                         fleshstuck=1;
9920                                                                                                                                                                 }
9921                                                                                                                                                         }
9922                                                                                                                                                         if(!fleshstuck){
9923                                                                                                                                                                 if(weapons.type[k]!=staff){
9924                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9925                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9926                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
9927                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
9928                                                                                                                                                                 }
9929                                                                                                                                                         }
9930                                                                                                                                                         if(fleshstuck){
9931                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
9932                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
9933                                                                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
9934                                                                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
9935                                                                                                                                                         }
9936
9937                                                                                                                                                         player[i].weaponactive=0;
9938                                                                                                                                                         if(weapons.owner[k]!=-1){
9939                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
9940                                                                                                                                                                 else player[i].victim->num_weapons=1;
9941
9942                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
9943                                                                                                                                                                 player[i].victim->skeleton.free=1;
9944                                                                                                                                                                 player[i].victim->skeleton.broken=0;
9945
9946                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
9947                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
9948                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
9949                                                                                                                                                                 }
9950
9951                                                                                                                                                                 XYZ relative;
9952                                                                                                                                                                 relative=0;
9953                                                                                                                                                                 relative.y=10;
9954                                                                                                                                                                 Normalise(&relative);
9955                                                                                                                                                                 XYZ footvel,footpoint;
9956                                                                                                                                                                 footvel=0;
9957                                                                                                                                                                 footpoint=weapons.position[k];
9958                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
9959                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
9960                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
9961                                                                                                                                                                                 weapons.bloody[k]=2;
9962                                                                                                                                                                                 weapons.blooddrip[k]=5;
9963                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
9964                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
9965                                                                                                                                                                                 player[i].victim->DoDamage(2000);
9966                                                                                                                                                                         }
9967                                                                                                                                                                 }
9968                                                                                                                                                                 if(player[i].victim->num_weapons>0){
9969                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
9970                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
9971                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
9972                                                                                                                                                                 }
9973
9974                                                                                                                                                                 player[i].victim->weaponactive=-1;
9975
9976                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
9977                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
9978                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
9979                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
9980                                                                                                                                                         }
9981                                                                                                                                                         weapons.owner[k]=i;
9982                                                                                                                                                         if(player[i].num_weapons>0){
9983                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9984                                                                                                                                                         }
9985                                                                                                                                                         player[i].num_weapons++;
9986                                                                                                                                                         player[i].weaponids[0]=k;
9987                                                                                                                                                 }
9988                                                                                                                                         }
9989                                                                                                                                 }
9990                                                                                                         }
9991                                                                                         }
9992                                                                                 }
9993                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
9994                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
9995                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
9996                                                                                                         if(numplayers>1)
9997                                                                                                                 for(j=0;j<numplayers;j++){
9998                                                                                                                         if(i!=j)
9999                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
10000                                                                                                                                         if(hostile)
10001                                                                                                                                                 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)){
10002                                                                                                                                                         if(!player[i].isFlip()){
10003                                                                                                                                                                 player[i].throwtogglekeydown=1;
10004                                                                                                                                                                 player[i].victim=&player[j];
10005                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10006                                                                                                                                                                 player[i].target=0;
10007                                                                                                                                                                 player[i].targetframe=0;
10008                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10009                                                                                                                                                                 Normalise(&rotatetarget);
10010                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10011                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10012                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10013
10014                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10015                                                                                                                                                         }
10016                                                                                                                                                         if(player[i].isFlip()){
10017                                                                                                                                                                 if(player[i].weaponactive!=-1){
10018                                                                                                                                                                         player[i].throwtogglekeydown=1;
10019                                                                                                                                                                         player[i].victim=&player[j];
10020                                                                                                                                                                         XYZ aim;
10021                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10022                                                                                                                                                                         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);
10023                                                                                                                                                                         Normalise(&aim);
10024
10025                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10026
10027                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10028                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10029                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10030                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10031                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10032                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10033                                                                                                                                                                         player[i].num_weapons--;
10034                                                                                                                                                                         if(player[i].num_weapons){
10035                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10036                                                                                                                                                                         }
10037                                                                                                                                                                         player[i].weaponactive=-1;
10038                                                                                                                                                                 }
10039                                                                                                                                                         }
10040                                                                                                                                                 }
10041                                                                                                                 }
10042                                                                                         }
10043                                                                                 }
10044                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10045                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10046                                                                                         {
10047                                                                                                 player[i].throwtogglekeydown=1;
10048                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10049                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10050                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10051                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10052                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10053                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10054                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10055                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10056                                                                                                 player[i].num_weapons--;
10057                                                                                                 if(player[i].num_weapons){
10058                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10059                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10060                                                                                                 }
10061
10062                                                                                                 player[i].weaponactive=-1;
10063                                                                                                 for(j=0;j<numplayers;j++){
10064                                                                                                         player[j].wentforweapon=0;
10065                                                                                                 }
10066                                                                                         }
10067                                                                                 }
10068
10069                                                                         }
10070
10071                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10072                                                                                 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)){
10073                                                                                         //Setenvironment(1-environment);
10074                                                                                         bool isgood;
10075                                                                                         isgood=1;
10076                                                                                         if(player[i].weaponactive!=-1){
10077                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10078                                                                                         }
10079                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10080                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10081                                                                                                         player[i].targetanimation=drawrightanim;
10082                                                                                                         player[i].targetframe=0;
10083                                                                                                         player[i].target=0;
10084                                                                                                         player[i].drawtogglekeydown=1;
10085                                                                                                 }
10086                                                                                                 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){
10087                                                                                                         player[i].targetanimation=drawleftanim;
10088                                                                                                         player[i].targetframe=0;
10089                                                                                                         player[i].target=0;
10090                                                                                                         player[i].drawtogglekeydown=1;
10091                                                                                                 }
10092                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10093                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10094                                                                                                         player[i].targetframe=0;
10095                                                                                                         player[i].target=0;
10096                                                                                                         player[i].drawtogglekeydown=1;
10097                                                                                                 }
10098                                                                                         }
10099                                                                                 }
10100                                                                                 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){
10101                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10102                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10103                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10104                                                                                                 player[i].targetframe=0;
10105                                                                                                 player[i].target=0;
10106                                                                                                 player[i].hasvictim=0;
10107                                                                                                 //player[i].attacktogglekeydown=1;
10108                                                                                         }
10109                                                                                 }
10110
10111                                                                                 if(!player[i].drawkeydown){
10112                                                                                         player[i].drawtogglekeydown=0;
10113                                                                                 }
10114
10115                                                                                 if(i==0){
10116                                                                                         absflatfacing=0;
10117                                                                                         absflatfacing.z=-1;
10118
10119                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10120                                                                                 }
10121                                                                                 else absflatfacing=flatfacing;
10122
10123                                                                                 if(indialogue!=-1){
10124                                                                                         player[i].forwardkeydown=0;
10125                                                                                         player[i].leftkeydown=0;
10126                                                                                         player[i].backkeydown=0;
10127                                                                                         player[i].rightkeydown=0;
10128                                                                                         player[i].jumpkeydown=0;
10129                                                                                         player[i].crouchkeydown=0;
10130                                                                                         player[i].drawkeydown=0;
10131                                                                                         player[i].throwkeydown=0;
10132                                                                                 }
10133                                                                                 movekey=0;
10134                                                                                 //Do controls
10135                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10136                                                                                         if(!player[i].forwardkeydown){
10137                                                                                                 player[i].forwardstogglekeydown=0;
10138                                                                                         }
10139                                                                                         if(player[i].crouchkeydown){
10140                                                                                                 //Crouch
10141                                                                                                 target=-2;
10142                                                                                                 if(i==0){
10143                                                                                                         player[i].superruntoggle=1;
10144                                                                                                         if(numplayers>1)
10145                                                                                                                 for(j=0;j<numplayers;j++){
10146                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10147                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10148                                                                                                                                         player[i].superruntoggle=0;
10149                                                                                                                                 }
10150                                                                                                                         }
10151                                                                                                                 }
10152                                                                                                 }
10153
10154                                                                                                 if(numplayers>1)
10155                                                                                                         for(j=0;j<numplayers;j++){
10156                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10157                                                                                                                         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))){
10158                                                                                                                                 if(target>=0)target=-1;
10159                                                                                                                                 else target=j;
10160                                                                                                                         }
10161                                                                                                                 }
10162                                                                                                         }
10163                                                                                                         if(target>=0)player[target].Reverse();
10164                                                                                                         player[i].lowreversaldelay=.5;
10165
10166                                                                                                         if(player[i].isIdle()){
10167                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10168                                                                                                                 player[i].target=0;
10169                                                                                                                 player[i].targetframe=0;
10170                                                                                                                 player[i].transspeed=10;
10171                                                                                                         }
10172                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10173                                                                                                                 player[i].targetanimation=rollanim;
10174                                                                                                                 player[i].target=0;
10175                                                                                                                 player[i].targetframe=0;
10176                                                                                                                 player[i].transspeed=20;
10177                                                                                                         }
10178                                                                                         }
10179                                                                                         if(!player[i].crouchkeydown){
10180                                                                                                 //Uncrouch
10181                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10182                                                                                                 target=-2;
10183                                                                                                 if(player[i].isCrouch()){
10184                                                                                                         if(numplayers>1)
10185                                                                                                                 for(j=0;j<numplayers;j++){
10186                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10187                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10188                                                                                                                                         if(target>=0)target=-1;
10189                                                                                                                                         else target=j;
10190                                                                                                                                 }
10191                                                                                                                         }
10192                                                                                                                 }
10193                                                                                                                 if(target>=0)player[target].Reverse();
10194                                                                                                                 player[i].highreversaldelay=.5;
10195
10196                                                                                                                 if(player[i].isCrouch()){
10197                                                                                                                         if(!player[i].wasCrouch()){
10198                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10199                                                                                                                                 player[i].currentframe=0;
10200                                                                                                                         }
10201                                                                                                                         player[i].target=0;
10202                                                                                                                         player[i].targetanimation=player[i].getIdle();
10203                                                                                                                         player[i].targetframe=0;
10204                                                                                                                         player[i].transspeed=10;
10205                                                                                                                 }
10206                                                                                                 }
10207                                                                                                 if(player[i].targetanimation==sneakanim){
10208                                                                                                         player[i].targetanimation=player[i].getIdle();
10209                                                                                                         player[i].target=0;
10210                                                                                                         player[i].targetframe=0;
10211                                                                                                         player[i].transspeed=10;
10212                                                                                                 }
10213                                                                                         }
10214                                                                                         if(player[i].forwardkeydown){
10215                                                                                                 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)){
10216                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10217                                                                                                         else player[i].targetanimation=player[i].getRun();
10218                                                                                                         player[i].target=0;
10219                                                                                                         player[i].targetframe=0;
10220                                                                                                 }
10221                                                                                                 if(player[i].isCrouch()){
10222                                                                                                         player[i].targetanimation=sneakanim;
10223                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10224                                                                                                         player[i].targetframe=0;
10225                                                                                                 }
10226                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10227                                                                                                         player[i].targetanimation=climbanim;
10228                                                                                                         player[i].target=0;
10229                                                                                                         player[i].targetframe=1;
10230                                                                                                         player[i].jumpclimb=1;
10231                                                                                                 }
10232                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10233                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10234                                                                                                 }
10235                                                                                                 player[i].forwardstogglekeydown=1;
10236                                                                                                 movekey=1;
10237                                                                                         }
10238                                                                                         if (player[i].rightkeydown){
10239                                                                                                 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)){
10240                                                                                                         player[i].targetanimation=player[i].getRun();
10241                                                                                                         player[i].target=0;
10242                                                                                                         player[i].targetframe=0;
10243                                                                                                 }
10244                                                                                                 if(player[i].isCrouch()){
10245                                                                                                         player[i].targetanimation=sneakanim;
10246                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10247                                                                                                         player[i].targetframe=0;
10248                                                                                                 }
10249                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10250                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10251                                                                                                 }
10252                                                                                                 player[i].targetrotation-=90;
10253                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10254                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10255                                                                                                 movekey=1;
10256                                                                                         }
10257                                                                                         if ( player[i].leftkeydown){
10258                                                                                                 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)){
10259                                                                                                         player[i].targetanimation=player[i].getRun();
10260                                                                                                         player[i].target=0;
10261                                                                                                         player[i].targetframe=0;
10262                                                                                                 }
10263                                                                                                 if(player[i].isCrouch()){
10264                                                                                                         player[i].targetanimation=sneakanim;
10265                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10266                                                                                                         player[i].targetframe=0;
10267                                                                                                 }
10268                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10269                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10270                                                                                                 }
10271                                                                                                 player[i].targetrotation+=90;
10272                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10273                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10274                                                                                                 movekey=1;
10275                                                                                         }
10276                                                                                         if(player[i].backkeydown){
10277                                                                                                 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)){
10278                                                                                                         player[i].targetanimation=player[i].getRun();
10279                                                                                                         player[i].target=0;
10280                                                                                                         player[i].targetframe=0;
10281                                                                                                 }
10282                                                                                                 if(player[i].isCrouch()){
10283                                                                                                         player[i].targetanimation=sneakanim;
10284                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10285                                                                                                         player[i].targetframe=0;
10286                                                                                                 }
10287                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10288                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10289                                                                                                 }
10290                                                                                                 if(player[i].targetanimation==hanganim){
10291                                                                                                         player[i].currentanimation=jumpdownanim;
10292                                                                                                         player[i].targetanimation=jumpdownanim;
10293                                                                                                         player[i].target=0;
10294                                                                                                         player[i].currentframe=0;
10295                                                                                                         player[i].targetframe=1;
10296                                                                                                         player[i].velocity=0;
10297                                                                                                         player[i].velocity.y+=gravity;
10298                                                                                                         player[i].coords.y-=1.4;
10299                                                                                                         player[i].grabdelay=1;
10300                                                                                                 }
10301                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10302                                                                                                         player[i].targetrotation+=180;
10303                                                                                                 movekey=1;
10304                                                                                         }
10305                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10306                                                                                                 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)){
10307                                                                                                         player[i].jumpstart=0;
10308                                                                                                         player[i].targetanimation=jumpupanim;
10309                                                                                                         player[i].target=0;
10310                                                                                                         player[i].targetframe=0;
10311                                                                                                         player[i].rotation=player[i].targetrotation;
10312                                                                                                         player[i].transspeed=20;
10313                                                                                                         player[i].FootLand(0,1);
10314                                                                                                         player[i].FootLand(1,1);
10315
10316                                                                                                         facing=0;
10317                                                                                                         facing.z=-1;
10318                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10319
10320                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10321                                                                                                         if(!movekey)player[i].velocity=0;
10322
10323                                                                                                         //Dodge sweep?
10324                                                                                                         target=-2;
10325                                                                                                         if(numplayers>1)
10326                                                                                                                 for(j=0;j<numplayers;j++){
10327                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10328                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10329                                                                                                                                         if(target>=0)target=-1;
10330                                                                                                                                         else target=j;
10331                                                                                                                                 }
10332                                                                                                                         }
10333                                                                                                                 }
10334                                                                                                                 if(target>=0)player[i].velocity.y=1;
10335                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10336                                                                                                                         player[i].velocity.y=7;
10337                                                                                                                         player[i].crouchtogglekeydown=1;
10338                                                                                                                 }
10339                                                                                                                 else player[i].velocity.y=5;
10340
10341                                                                                                                 if(mousejump&&i==0&&debugmode){
10342                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10343                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10344                                                                                                                 }
10345
10346                                                                                                                 player[i].coords.y+=.2;
10347                                                                                                                 player[i].jumppower-=1;
10348
10349                                                                                                                 static float gLoc[3];
10350                                                                                                                 static float vel[3];
10351                                                                                                                 gLoc[0]=player[i].coords.x;
10352                                                                                                                 gLoc[1]=player[i].coords.y;
10353                                                                                                                 gLoc[2]=player[i].coords.z;
10354                                                                                                                 vel[0]=player[i].velocity.x;
10355                                                                                                                 vel[1]=player[i].velocity.y;
10356                                                                                                                 vel[2]=player[i].velocity.z;
10357
10358                                                                                                                 if(i==0){
10359                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
10360                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10361                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
10362                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
10363                                                                                                                 }
10364
10365                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
10366                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10367                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
10368                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
10369                                                                                                 }
10370                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10371                                                                                                         player[i].targetanimation=player[i].getLanding();
10372                                                                                                         player[i].landhard=0;
10373                                                                                                         player[i].target=0;
10374                                                                                                         player[i].targetframe=2;
10375                                                                                                         player[i].jumpstart=1;
10376                                                                                                         player[i].tempdeltav=deltav;
10377                                                                                                 }
10378                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10379                                                                                                         if(player[i].jumppower>multiplier*6){
10380                                                                                                                 player[i].velocity.y+=multiplier*6;
10381                                                                                                                 player[i].jumppower-=multiplier*6;
10382                                                                                                         }
10383                                                                                                         if(player[i].jumppower<=multiplier*6){
10384                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10385                                                                                                                 player[i].jumppower=0;
10386                                                                                                         }
10387                                                                                                 }
10388                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
10389                                                                                         }
10390
10391                                                                                         if(!movekey){
10392                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10393                                                                                                         player[i].targetanimation=player[i].getStop();
10394                                                                                                         player[i].target=0;
10395                                                                                                         player[i].targetframe=0;
10396                                                                                                 }
10397                                                                                                 if(player[i].targetanimation==sneakanim){
10398                                                                                                         player[i].targetanimation=player[i].getCrouch();
10399                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10400                                                                                                         player[i].targetframe=0;
10401                                                                                                 }
10402                                                                                         }
10403                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10404                                                                                                 player[i].targetanimation=player[i].getStop();
10405                                                                                                 player[i].target=0;
10406                                                                                                 player[i].targetframe=0;
10407                                                                                         }
10408                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10409                                                                                                 player[i].targetanimation=player[i].getStop();
10410                                                                                                 player[i].target=0;
10411                                                                                                 player[i].targetframe=0;
10412                                                                                         }
10413                                                                                 }
10414                                                                 }
10415                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10416                                                         }
10417
10418                                                         //Rotation
10419                                                         for(k=0;k<numplayers;k++){
10420                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10421                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10422                                                                         else player[k].rotation+=360;
10423                                                                 }
10424
10425                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10426                                                                         player[k].targetanimation=player[k].getStop();
10427                                                                         player[k].targetframe=0;
10428                                                                         player[k].target=0;
10429                                                                 }
10430
10431                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10432                                                                         player[k].targettilt=0;
10433                                                                 }
10434                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10435                                                                         player[k].targettilt=0;
10436                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10437                                                                         player[k].jumppower+=multiplier*7;
10438                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10439                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10440                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10441                                                                 }
10442
10443                                                                 if(player[k].isRun()){
10444                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10445                                                                 }
10446
10447                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10448                                                                 else if(player[k].tilt>player[k].targettilt){
10449                                                                         player[k].tilt-=multiplier*150;
10450                                                                 }
10451                                                                 else if(player[k].tilt<player[k].targettilt){
10452                                                                         player[k].tilt+=multiplier*150;
10453                                                                 }
10454
10455                                                                 player[k].grabdelay-=multiplier;
10456                                                         }
10457
10458                                                         for(k=0;k<numplayers;k++){
10459                                                                 player[k].DoAnimations();
10460                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10461                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10462                                                         }
10463
10464                                                         objects.DoStuff();
10465                                                         /*
10466                                                         player[0].righthandmorphstart=0;
10467                                                         player[0].righthandmorphend=1;
10468                                                         player[0].lefthandmorphstart=0;
10469                                                         player[0].lefthandmorphend=1;
10470                                                         player[0].headmorphstart=0;
10471                                                         player[0].headmorphend=2;*/
10472
10473                                                         /*
10474                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10475                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10476                                                         player[0].righthandmorphend=1;
10477                                                         player[0].targetrighthandmorphness=1;
10478
10479                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10480                                                         player[0].lefthandmorphend=0;
10481                                                         player[0].targetlefthandmorphness=1;
10482
10483                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10484                                                         player[0].headmorphend=2;
10485                                                         player[0].targetheadmorphness=1;
10486                                                         }
10487                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10488                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10489                                                         player[0].righthandmorphend=0;
10490                                                         player[0].targetrighthandmorphness=1;
10491
10492                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10493                                                         player[0].lefthandmorphend=1;
10494                                                         player[0].targetlefthandmorphness=1;
10495
10496                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10497                                                         player[0].headmorphend=0;
10498                                                         player[0].targetheadmorphness=1;
10499                                                         }
10500                                                         */
10501                                                         if(numenvsounds!=0)
10502                                                                 for(j=numenvsounds-1;j>=0;j--){
10503                                                                         envsoundlife[j]-=multiplier;
10504                                                                         if(envsoundlife[j]<0){
10505                                                                                 numenvsounds--;
10506                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10507                                                                                 envsound[j]=envsound[numenvsounds];
10508                                                                         }
10509                                                                 }
10510                                                                 if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
10511                                                                 if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
10512
10513                                                                 if(tutoriallevel==1){
10514                                                                         XYZ temp;
10515                                                                         XYZ temp2;
10516                                                                         XYZ temp3;
10517                                                                         XYZ oldtemp;
10518                                                                         XYZ oldtemp2;
10519                                                                         temp.x=1011;
10520                                                                         temp.y=84;
10521                                                                         temp.z=491;
10522                                                                         temp2.x=1025;
10523                                                                         temp2.y=75;
10524                                                                         temp2.z=447;
10525                                                                         temp3.x=1038;
10526                                                                         temp3.y=76;
10527                                                                         temp3.z=453;
10528                                                                         oldtemp=temp;
10529                                                                         oldtemp2=temp2;
10530                                                                         if(tutorialstage>=51)
10531                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10532                                                     OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
10533                                                                                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
10534
10535                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10536                                                                                         OPENAL_SetPaused(channels[stream_music3], false);
10537                                                                                         OPENAL_SetVolume(channels[stream_music3], 256);
10538
10539                                                                                         gameon=0;
10540                                                                                         mainmenu=5;
10541
10542                                                                                         float gLoc[3]={0,0,0};
10543                                                                                         float vel[3]={0,0,0};
10544                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10545                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10546                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10547                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10548                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10549                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10550
10551                                                                                         flashr=1;
10552                                                                                         flashg=0;
10553                                                                                         flashb=0;
10554                                                                                         flashamount=1;
10555                                                                                         flashdelay=1;
10556                                                                                 }
10557                                                                                 if(tutorialstage<51)
10558                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10559                                                                                                 float gLoc[3];
10560                                                                                                 float vel[3];
10561                                                                                                 gLoc[0]=player[0].coords.x;
10562                                                                                                 gLoc[1]=player[0].coords.y;
10563                                                                                                 gLoc[2]=player[0].coords.z;
10564                                                                                                 vel[0]=0;
10565                                                                                                 vel[1]=0;
10566                                                                                                 vel[2]=0;
10567                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10568                                                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10569                                                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10570                                                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10571
10572                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10573
10574                                                                                                 flashr=1;
10575                                                                                                 flashg=1;
10576                                                                                                 flashb=1;
10577                                                                                                 flashamount=1;
10578                                                                                                 flashdelay=1;
10579                                                                                         }
10580                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10581                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10582                                                                                                         float gLoc[3];
10583                                                                                                         float vel[3];
10584                                                                                                         gLoc[0]=player[1].coords.x;
10585                                                                                                         gLoc[1]=player[1].coords.y;
10586                                                                                                         gLoc[2]=player[1].coords.z;
10587                                                                                                         vel[0]=0;
10588                                                                                                         vel[1]=0;
10589                                                                                                         vel[2]=0;
10590                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10591                                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10592                                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10593                                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10594
10595                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10596                                                                                                                 if(Random()%2==0){
10597                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10598                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10599                                                                                                                         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;
10600                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10601                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10602                                                                                                                 }
10603                                                                                                         }
10604
10605                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10606                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10607                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10608                                                                                                                 if(Random()%2==0){
10609                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10610                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10611                                                                                                                         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;
10612                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10613                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10614                                                                                                                 }
10615                                                                                                         }
10616                                                                                                 }
10617                                                                 }
10618
10619
10620                                                                 //3d sound
10621                                                                 static float gLoc[3];
10622                                                                 gLoc[0]=viewer.x;
10623                                                                 gLoc[1]=viewer.y;
10624                                                                 gLoc[2]=viewer.z;
10625                                                                 static float vel[3];
10626                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10627                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10628                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10629
10630                                                                 //Set orientation with forward and up vectors
10631                                                                 static XYZ upvector;
10632                                                                 upvector=0;
10633                                                                 upvector.z=-1;
10634
10635                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10636                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10637
10638                                                                 facing=0;
10639                                                                 facing.z=-1;
10640
10641                                                                 facing=DoRotation(facing,-rotation2,0,0);
10642                                                                 facing=DoRotation(facing,0,0-rotation,0);
10643
10644
10645                                                                 static float ori[6];
10646                                                                 ori[0] = -facing.x;
10647                                                                 ori[1] = facing.y;
10648                                                                 ori[2] = -facing.z;
10649                                                                 ori[3] = -upvector.x;
10650                                                                 ori[4] = upvector.y;
10651                                                                 ori[5] = -upvector.z;
10652
10653                                                                 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10654                                                                 OPENAL_Update();
10655
10656                                                                 oldviewer=viewer;
10657                 }
10658         }
10659
10660         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10661                 Screenshot();
10662                 freezetogglekeydown=1;
10663         }
10664 }
10665
10666 void    Game::TickOnce(){
10667         //if(!console){
10668         if(!mainmenu)
10669                 if(directing||indialogue==-1){
10670                         rotation+=deltah*.7;
10671                         if(!invertmouse)rotation2+=deltav*.7;
10672                         if(invertmouse)rotation2-=deltav*.7;
10673                         if(rotation2>90)rotation2=90;
10674                         if(rotation2<-70)rotation2=-70;
10675                 }
10676                 if(mainmenu)rotation+=multiplier*5;
10677       
10678                 //}
10679 }
10680
10681 void    Game::TickOnceAfter(){
10682         static XYZ colviewer;
10683         static XYZ coltarget;
10684         static XYZ target;
10685         static XYZ col;
10686         static float brotate;
10687         static XYZ facing;
10688         static int i,j;
10689         static float changedelay;
10690         static bool alldead;
10691         static float unseendelay;
10692         static float cameraspeed;
10693
10694         if(!mainmenu){
10695
10696                 if(environment==snowyenvironment)music1=stream_music1snow;
10697                 if(environment==grassyenvironment)music1=stream_music1grass;
10698                 if(environment==desertenvironment)music1=stream_music1desert;
10699
10700                 realthreat=0;
10701
10702                 musictype=music1;
10703                 for(i=0;i<numplayers;i++){
10704                         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)){
10705                                 musictype=stream_music2;
10706                                 realthreat=1;
10707                         }
10708                 }
10709                 if(player[0].dead)musictype=stream_music3;
10710
10711
10712                 if(musictype==stream_music2){
10713                         unseendelay=1;
10714                 }
10715
10716                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
10717                         unseendelay-=multiplier;
10718                         if(unseendelay>0){
10719                                 musictype=stream_music2;
10720                         }
10721                 }
10722
10723
10724                 if(loading==2){
10725                         musictype=stream_music3;
10726                         musicvolume[2]=512;
10727                         musicvolume[0]=0;
10728                         musicvolume[1]=0;
10729                         musicvolume[3]=0;
10730                 }
10731
10732                 if(musictoggle){
10733                         if(musictype!=oldmusictype&&musictype==stream_music2){
10734                                 static float gLoc[3];
10735                                 static float vel[3];
10736                                 gLoc[0]=cameraloc.x;
10737                                 gLoc[1]=cameraloc.y;
10738                                 gLoc[2]=cameraloc.z;
10739                                 vel[0]=0;
10740                                 vel[1]=0;
10741                                 vel[2]=0;
10742                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
10743                                 OPENAL_SetVolume(channels[alarmsound], 512);
10744                                 OPENAL_SetPaused(channels[alarmsound], false);
10745
10746                         }
10747                 }
10748                 musicselected=musictype;
10749
10750                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
10751                 else musicvolume[0]-=multiplier*450;
10752                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
10753                 else musicvolume[1]-=multiplier*450;
10754                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
10755                 else musicvolume[2]-=multiplier*450;
10756                 /*
10757                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
10758                 else musicvolume[0]-=multiplier*450;
10759                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
10760                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
10761                 else musicvolume[1]-=multiplier*100;
10762                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
10763                 else musicvolume[2]-=multiplier*450;*/
10764
10765                 for(i=0;i<3;i++){
10766                         if(musicvolume[i]<0)musicvolume[i]=0;
10767                         if(musicvolume[i]>512)musicvolume[i]=512;
10768                 }
10769
10770                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
10771
10772                 if(musictoggle){
10773                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
10774                                 PlayStreamEx( music1, strm[music1], NULL, true);
10775                                 OPENAL_SetPaused(channels[music1], false);
10776                         }
10777                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
10778                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
10779                                 OPENAL_SetPaused(channels[stream_music2], false);
10780                         }
10781                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
10782                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10783                                 OPENAL_SetPaused(channels[stream_music3], false);
10784                         }
10785                 }
10786
10787                 if(!musictoggle){
10788                         OPENAL_SetPaused(channels[music1], true);
10789                         OPENAL_SetPaused(channels[stream_music2], true);
10790                         OPENAL_SetPaused(channels[stream_music3], true);
10791
10792                         for(i=0;i<4;i++){
10793                                 oldmusicvolume[i]=0;
10794                                 musicvolume[i]=0;
10795                         }
10796                 }
10797
10798                 if(musictoggle){
10799                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
10800                                 OPENAL_SetPaused(channels[music1], true);
10801                         }
10802                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
10803                                 OPENAL_SetPaused(channels[stream_music2], true);
10804                         }
10805                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
10806                                 OPENAL_SetPaused(channels[stream_music3], true);
10807                         }
10808
10809                         if(musicvolume[0]!=oldmusicvolume[0]){
10810                                 OPENAL_SetVolume(channels[music1], musicvolume[0]);
10811                         }
10812                         if(musicvolume[1]!=oldmusicvolume[1]){
10813                                 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
10814                         }
10815                         if(musicvolume[2]!=oldmusicvolume[2]){
10816                                 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
10817                         }
10818
10819                         for(i=0;i<3;i++){
10820                                 oldmusicvolume[i]=musicvolume[i];
10821                         }
10822                 }
10823
10824                 killhotspot=2;
10825                 if(numhotspots)
10826                         for(i=0;i<numhotspots;i++){
10827                                 if(hotspottype[i]>10&&hotspottype[i]<20){
10828                                         if(player[hotspottype[i]-10].dead==0){
10829                                                 killhotspot=0;
10830                                         }
10831                                         else if(killhotspot==2)
10832                                                 killhotspot=1;
10833                                 }
10834                         }
10835                         if(killhotspot==2)killhotspot=0;
10836
10837
10838                         winhotspot=0;
10839                         if(numhotspots)
10840                                 for(i=0;i<numhotspots;i++){
10841                                         if(hotspottype[i]==-1){
10842                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
10843                                                         winhotspot=1;
10844                                         }
10845                                 }
10846
10847                                 int numalarmed=0;
10848                                 if(numplayers>1)
10849                                         for(i=1;i<numplayers;i++){
10850                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
10851                                         }
10852                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
10853
10854                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
10855                                                 if(player[0].dead&&changedelay<=0){
10856                                                         changedelay=1;
10857                                                         targetlevel=whichlevel;
10858                                                 }
10859                                                 alldead=1;
10860                                                 if(numplayers>1)
10861                                                         for(i=1;i<numplayers;i++){
10862                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
10863                                                         }
10864
10865
10866                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
10867                                                                 changedelay=1;
10868                                                                 targetlevel=whichlevel+1;
10869                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10870                                                         }
10871                                                         if(winhotspot||windialogue){
10872                                                                 changedelay=0.1;
10873                                                                 targetlevel=whichlevel+1;
10874                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10875                                                         }
10876
10877
10878                                                         if(killhotspot){
10879                                                                 changedelay=1;
10880                                                                 targetlevel=whichlevel+1;
10881                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10882                                                         }
10883
10884                                                         if(changedelay>0&&!player[0].dead&&!won){
10885                                                                 //high scores, awards, win
10886                                                                 if(campaign){
10887                                                                         won=1;
10888                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
10889                                                                         accountcampaignchoicesmade[accountactive]++;
10890                                                                         accountcampaignscore[accountactive]+=bonustotal;
10891                                                                         scoreadded=1;
10892                                                                         accountcampaigntime[accountactive]+=leveltime;
10893                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
10894
10895                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
10896                                                                 }
10897                                                                 else
10898                                                                 {
10899                                                                         won=1;
10900                                                                         if(!debugmode){
10901                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
10902                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;
10903                                                                         }
10904                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
10905
10906                                                                 }
10907                                                         }
10908                                         }
10909
10910                                         if(!winfreeze){
10911
10912                                                 if(leveltime<1){
10913                                                         loading=0;
10914                                                         changedelay=.1;
10915                                                         alldead=0;
10916                                                         winhotspot=0;
10917                                                         killhotspot=0;
10918                                                 }
10919
10920                                                 if(!editorenabled&&gameon&&!mainmenu){
10921                                                         if(changedelay!=-999)changedelay-=multiplier/7;
10922                                                         if(player[0].dead)targetlevel=whichlevel;
10923                                                         if(loading==2&&!campaign){
10924                                                                 flashr=1;
10925                                                                 flashg=0;
10926                                                                 flashb=0;
10927                                                                 flashamount=1;
10928                                                                 flashdelay=1;
10929                                                                 loadtime=0;
10930
10931                                                                 float gLoc[3]={0,0,0};
10932                                                                 float vel[3]={0,0,0};
10933                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10934                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10935                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10936                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
10937                                                                 OPENAL_SetPaused(channels[firestartsound], false);
10938                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10939
10940                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
10941                                                                         startbonustotal=bonustotal;
10942                                                                 }
10943                                                                 if(!player[0].dead)Loadlevel(targetlevel);
10944                                                                 if(player[0].dead)Loadlevel(whichlevel);
10945
10946                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10947                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10948                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10949                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10950                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10951                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10952
10953                                                                 loading=3;
10954                                                         }
10955                                                         if(loading==2&&targetlevel==whichlevel){
10956                                                                 flashr=1;
10957                                                                 flashg=0;
10958                                                                 flashb=0;
10959                                                                 flashamount=1;
10960                                                                 flashdelay=1;
10961                                                                 loadtime=0;
10962
10963                                                                 float gLoc[3]={0,0,0};
10964                                                                 float vel[3]={0,0,0};
10965                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10966                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10967                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10968                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
10969                                                                 OPENAL_SetPaused(channels[firestartsound], false);
10970                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10971
10972                                                                 for(i=0;i<255;i++){
10973                                                                         mapname[i]='\0';
10974                                                                 }
10975                                                                 mapname[0]=':';
10976                                                                 mapname[1]='D';
10977                                                                 mapname[2]='a';
10978                                                                 mapname[3]='t';
10979                                                                 mapname[4]='a';
10980                                                                 mapname[5]=':';
10981                                                                 mapname[6]='M';
10982                                                                 mapname[7]='a';
10983                                                                 mapname[8]='p';
10984                                                                 mapname[9]='s';
10985                                                                 mapname[10]=':';
10986                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
10987                                                                 Loadlevel(mapname);
10988
10989                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10990                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10991                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10992                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10993                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10994                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10995
10996                                                                 loading=3;
10997                                                         }
10998                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
10999                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
11000                         {
11001                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
11002                                                                                 winfreeze=1;
11003                                                                                 changedelay=-999;
11004                                                                         }
11005                                                                         if(player[0].dead)loading=1;
11006                                                                 }
11007                                                         }
11008                                                 }
11009
11010                                                 if(campaign)
11011                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11012                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11013                                                                         endgame=1;
11014                                                                 }
11015                                                         }
11016                                                         else if(mainmenu==0&&winfreeze){
11017                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11018                                                                         stealthloading=1;
11019                                                                 else stealthloading=0;
11020
11021                                                                 if(!stealthloading){
11022                                                                         float gLoc[3]={0,0,0};
11023                                                                         float vel[3]={0,0,0};
11024                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11025                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11026                                                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11027                                                                         OPENAL_SetVolume(channels[firestartsound], 256);
11028                                                                         OPENAL_SetPaused(channels[firestartsound], false);
11029                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11030
11031                                                                         flashr=1;
11032                                                                         flashg=0;
11033                                                                         flashb=0;
11034                                                                         flashamount=1;
11035                                                                         flashdelay=1;
11036                                                                 }
11037
11038                                                                 startbonustotal=0;
11039
11040                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
11041                                                                 //campaignnumlevels=0;
11042                                                                 //accountcampaignchoicesmade[accountactive]=0;
11043                                                                 ipstream.ignore(256,':');
11044                                                                 ipstream >> campaignnumlevels;
11045                                                                 for(i=0;i<campaignnumlevels;i++){
11046                                                                         ipstream.ignore(256,':');
11047                                                                         ipstream.ignore(256,':');
11048                                                                         ipstream.ignore(256,' ');
11049                                                                         ipstream >> campaignmapname[i];
11050                                                                         ipstream.ignore(256,':');
11051                                                                         ipstream >> campaigndescription[i];
11052                                                                         for(j=0;j<256;j++){
11053                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11054                                                                         }
11055                                                                         ipstream.ignore(256,':');
11056                                                                         ipstream >> campaignchoosenext[i];
11057                                                                         ipstream.ignore(256,':');
11058                                                                         ipstream >> campaignnumnext[i];
11059                                                                         if(campaignnumnext[i])
11060                                                                                 for(j=0;j<campaignnumnext[i];j++){
11061                                                                                         ipstream.ignore(256,':');
11062                                                                                         ipstream >> campaignnextlevel[i][j];
11063                                                                                         campaignnextlevel[i][j]-=1;
11064                                                                                 }
11065                                                                                 ipstream.ignore(256,':');
11066                                                                                 ipstream >> campaignlocationx[i];
11067                                                                                 ipstream.ignore(256,':');
11068                                                                                 ipstream >> campaignlocationy[i];
11069                                                                 }
11070                                                                 ipstream.close();
11071
11072                                                                 for(i=0;i<campaignnumlevels;i++){
11073                                                                         levelvisible[i]=0;
11074                                                                         levelhighlight[i]=0;
11075                                                                 }
11076
11077
11078                                                                 for(i=0;i<campaignnumlevels;i++){
11079                                                                         levelvisible[i]=0;
11080                                                                         levelhighlight[i]=0;
11081                                                                 }
11082
11083                                                                 levelorder[0]=0;
11084                                                                 levelvisible[0]=1;
11085                                                                 if(accountcampaignchoicesmade[accountactive])
11086                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11087                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11088                                                                                 levelvisible[levelorder[i+1]]=1;
11089                                                                         }
11090                                                                         int whichlevelstart;
11091                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11092                                                                         if(whichlevelstart<0){
11093                                                                                 campaignchoicenum=1;
11094                                                                                 campaignchoicewhich[0]=0;
11095                                                                         }
11096                                                                         else
11097                                                                         {
11098                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11099                                                                                 if(campaignchoicenum)
11100                                                                                         for(i=0;i<campaignchoicenum;i++){
11101                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11102                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11103                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11104                                                                                         }
11105                                                                         }
11106
11107                                                                         loading=2;
11108                                                                         loadtime=0;
11109                                                                         targetlevel=7;
11110                                                                         //if(firstload)TickOnceAfter();
11111                                                                         if(!firstload)LoadStuff();
11112                                                                         //else {
11113                                                                         for(i=0;i<255;i++){
11114                                                                                 mapname[i]='\0';
11115                                                                         }
11116                                                                         mapname[0]=':';
11117                                                                         mapname[1]='D';
11118                                                                         mapname[2]='a';
11119                                                                         mapname[3]='t';
11120                                                                         mapname[4]='a';
11121                                                                         mapname[5]=':';
11122                                                                         mapname[6]='M';
11123                                                                         mapname[7]='a';
11124                                                                         mapname[8]='p';
11125                                                                         mapname[9]='s';
11126                                                                         mapname[10]=':';
11127
11128                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11129                                                                         //accountcampaignchoicesmade[accountactive]++;
11130
11131
11132                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11133                                                                         whichchoice=0;
11134                                                                         visibleloading=1;
11135                                                                         stillloading=1;
11136                                                                         Loadlevel(mapname);
11137                                                                         campaign=1;
11138                                                                         mainmenu=0;
11139                                                                         gameon=1;
11140                                                                         OPENAL_SetPaused(channels[stream_music3], true);
11141
11142                                                                         stealthloading=0;
11143                                                         }
11144
11145                                                         if(loading==3)loading=0;
11146
11147                                         }
11148
11149                                         oldmusictype=musictype;
11150         }
11151
11152         facing=0;
11153         facing.z=-1;
11154
11155         facing=DoRotation(facing,-rotation2,0,0);
11156         facing=DoRotation(facing,0,0-rotation,0);
11157         viewerfacing=facing;
11158
11159         brotate=0;
11160         if(!cameramode){
11161                 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;
11162                 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;
11163                 target.y+=.1;
11164                 if(player[0].skeleton.free){
11165                         for(i=0;i<player[0].skeleton.num_joints;i++){
11166                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
11167                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11168                         }
11169                         target.y+=.1;
11170                 }
11171                 if(player[0].skeleton.free!=2&&!autocam){
11172                         cameraspeed=20;
11173                         if(findLengthfast(&player[0].velocity)>400){
11174                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11175                         }
11176                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11177                         coltarget=target-cameraloc;
11178                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11179                         else {
11180                                 Normalise(&coltarget);
11181                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11182                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11183                         }
11184                         if(editorenabled)cameraloc=target;
11185                         cameradist+=multiplier*5;
11186                         if(cameradist>2.3)cameradist=2.3;
11187                         viewer=cameraloc-facing*cameradist;
11188                         colviewer=viewer;
11189                         coltarget=cameraloc;
11190                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11191                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11192                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11193                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11194                                         colviewer=viewer;
11195                                         coltarget=cameraloc;
11196                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11197                                 }
11198                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11199                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11200                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11201                                                 colviewer=viewer;
11202                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11203                                                         viewer=colviewer;
11204                                                 }
11205                                         }
11206                                         cameradist=findDistance(&viewer,&target);
11207                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11208                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11209                                         }
11210                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11211                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11212                                         }
11213                 }
11214                 if(player[0].skeleton.free!=2&&autocam){
11215                         cameraspeed=20;
11216                         if(findLengthfast(&player[0].velocity)>400){
11217                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11218                         }
11219                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11220                         cameradist+=multiplier*5;
11221                         if(cameradist>3.3)cameradist=3.3;
11222                         coltarget=target-cameraloc;
11223                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11224                         else if(findLengthfast(&coltarget)>1)
11225                         {
11226                                 Normalise(&coltarget);
11227                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11228                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11229                         }
11230                         if(editorenabled)cameraloc=target;
11231                         viewer=cameraloc;
11232                         colviewer=viewer;
11233                         coltarget=cameraloc;
11234                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11235                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11236                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11237                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11238                                         colviewer=viewer;
11239                                         coltarget=cameraloc;
11240                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11241                                 }
11242                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11243                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11244                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11245                                                 colviewer=viewer;
11246                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11247                                                         viewer=colviewer;
11248                                                 }
11249                                         }
11250                                         cameradist=findDistance(&viewer,&target);
11251                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11252                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11253                                         }
11254                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11255                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11256                                         }
11257                 }
11258                 if(camerashake>.8)camerashake=.8;
11259                 //if(woozy>10)woozy=10;
11260                 //woozy+=multiplier;
11261                 woozy+=multiplier;
11262                 if(player[0].dead)camerashake=0;
11263                 if(player[0].dead)woozy=0;
11264                 camerashake-=multiplier*2;
11265                 blackout-=multiplier*2;
11266                 //if(player[0].isCrouch())woozy-=multiplier*8;
11267                 if(camerashake<0)camerashake=0;
11268                 if(blackout<0)blackout=0;
11269                 //if(woozy<0)woozy=0;
11270                 if(camerashake){
11271                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11272                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11273                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11274                 }
11275         }
11276 }